tags:

views:

282

answers:

4

Hi, I am using C# .NET 2.0.I want to generate a PDF file . I should write a text in the file.

What are the prerequsites we need to generate the PDF.

Any simplae coding samples will help me.

PLease suggest opensource libraries.

Thanks in advance.

+1  A: 

UPDATE: SharpPDF looks dead. Go with PDFSharp instead...

This question has been asked a few times on SO:

SharpPDF - with tutorials here.

Mitch Wheat
It is created for .NET framework 1.1.Of course it can be used in other .NET versions, but still.
Sorantis
+4  A: 

Use PDFSharp

PDFsharp is the Open Source library that easily creates PDF documents from any .NET language. The same drawing routines can be used to create PDF documents, draw on the screen, or send output to any printer.

// Create a new PDF document
PdfDocument document = new PdfDocument();

// 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.Bold);

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

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

Samples

Sorantis
The link to PDFSharp is incorrect
edosoft
updated........
Sorantis
..."thanks for pointing that out guys" ....
Mitch Wheat
+1  A: 

I would recommend iTextSharp: http://sourceforge.net/projects/itextsharp/

It's a port of iText: http://www.lowagie.com/iText/

WowtaH
A: 

Hi, Sorry then i am closing the question.

Jebli