开发者

How Can I Create a PDF Quotation File from Winform?

alt text http://img517.imagesha开发者_如何学JAVAck.us/img517/8124/56267347.jpg

Assuming i have a winform that has a button called "Create a Quote". Once user clicks it, a PDF File gets created on desktop. The PDF File has a fixed design/structure e.g. the logo is at the top left corner, the headers are fixed, etc. However, the data it self is pulled from a database.

As you see above, Quotation #, Description, Qty, U.P (USD), T.P (USD) records should be fetched from the db and dumped in the pdf template then create the pdf for user.

I haven't done this before. I hope my question is clear enough. Feel free to put useful web links that help me achieve it.

Any help will be appreciated.


You should look at two of the most popular open-source PDF libraries for C#, namely:

ITextSharp and PDFSharp

Both allow you to programatically create PDF files. Here's a quick 'hello word' example with PDFSharp:

  // Create a new PDF document
  PdfDocument document = new PdfDocument();
  document.Info.Title = "Created with PDFsharp";

  // Create an empty page
  PdfPage page = document.AddPage();

  // Get an XGraphics object for drawing
  XGraphics gfx = XGraphics.FromPdfPage(page);

  // Create a font
  XFont font = new XFont("Verdana", 20, XFontStyle.BoldItalic);

  // Draw the text
  gfx.DrawString("Hello, World!", font, XBrushes.Black,
    new XRect(0, 0, page.Width, page.Height),
    XStringFormats.Center);

  // Save the document...
  const string filename = "HelloWorld.pdf";
  document.Save(filename);
  // ...and start a viewer.
  Process.Start(filename);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜