Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to write .pdf file in c#.net?
Posted

PDfSharp or ITextSharp would do the trick.

on PdfSharp is like this:

C#
class Program
  {
    static void Main(string[] args)
    {
   // 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);
    }
  } 


on ITextSharp is like this:

C#
iTextSharp.text.Document oDoc = new iTextSharp.text.Document();
PdfWriter.GetInstance(oDoc, new FileStream("HelloWorld.pdf", FileMode.Create));
oDoc.Open();
oDoc.Add(new Paragraph("Hello World!"));
oDoc.Close();


I have used them both, and must say both are great, but iTextSharp can also render a PDF to an image (rasterize). PdfSharp is faster and smaller also.

hope it helps.
 
Share this answer
 
v2
Comments
ErBhati 28-Jan-14 5:44am    
Thanks it give me a lot of relief.....
PDFSharp[^]. Nice library will help you create pdf easily.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900