Easily and quickly create a PDF document in Visual Studio C# Class.
PDF (Portable Document Format) is a file format that has replicate all the characteristics of a printed document that you can read, write, print or forward to someone else. You can create PDF file programmatically from C# applications very easily. When you create documents, graphics etc. they look just like they would if printed.
In XsPDF you are responsible for controlling every aspect of the rendering process which is done by drawing lines, strings and shapes at specified coordinates on a PDF graphics context. The toolkit has mimicked the Microsoft GDI+ interface and thus many of the APIs and objects will be familiar to developers with GDI+ experience.
XsPDF library allows you to create PDF files directly from your C# application.
// Create a new PDF document. PdfDocument document = new PdfDocument(); document.Info.Title = "Created with XsPDF SDK"; document.Info.Author = "sample"; // Create an empty page in this document. PdfPage page1 = document.AddPage(); // Obtain an XGraphics object to render to XGraphics g1 = XGraphics.FromPdfPage(page1); // Get the centre of the page double y = page1.Height / 2; //Draw one line in the center of page g1.DrawLine(XPens.Red, 0, y, page1.Width, y); // Create a font double fontHeight = 36; XFont font = new XFont("Times New Roman", fontHeight, XFontStyle.BoldItalic); // Create a rectangle to draw the text in and draw in it XRect rect = new XRect(0, y, page1.Width, fontHeight); g1.DrawString("This is the first page! ", font, XBrushes.Black, rect, XStringFormats.Center); // Create a second page in this document. PdfPage page2 = document.AddPage(); // Get an XGraphics object for drawing //You can customize each page content with graphics from each PDF page XGraphics g2 = XGraphics.FromPdfPage(page2); //Draw one line in the center of page g2.DrawLine(XPens.Red, 0, y, page1.Width, y); // Add different text in another page g2.DrawString("This is the second page! ", font, XBrushes.Black, rect, XStringFormats.Center); // Save and show the document document.Save("Sample-Document.pdf"); Process.Start("Sample-Document.pdf");
More PDF tutorial
- Area chart drawn to PDF page - Visual Studio .NET framework sample
- How to use XsPDF to Image Component for .NET to transform PDF page to high quality transparent png in Visual C#
- An empty page inserting to PDF in CSharp .NET is quite easy and quick using XsPDF source code for .NET
- Transforming high quality tiff file from PDF file using .NET C# and XsPDF DLL
- 1D/2D barcodes generated to PDF page - .NET C# tutorial
- Generating PDF 417 to PDF page using Visual C# and XsPDF Control
- Column diagram adding to PDF in C#.NET is quite easy and quick using XsPDF Chart DLL for .NET
- How to use XsPDF Component for .NET to compress PDF in .NET
- How to use XsPDF Component for .NET to generate multiple image formats to PDF in .NET Visual C#
- Data Matrix ECC200 created to PDF page - .NET C# demo
- Charactors extracting from PDF in Visual Studio .NET framework is quite easy and quick using XsPDF Library for .NET
- .NET Visual C# sample for generating PDF file from html5
- .NET sample code for creating EAN-128 to PDF page
- Png reading from PDF in Visual C# is quite easy and quick using XsPDF SDK for .NET
- Make Clustered Column graphs to PDF in C#