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.
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
UPDATE: SharpPDF looks dead. Go with PDFSharp instead...
This question has been asked a few times on SO:
SharpPDF - with tutorials here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With