C#: Online Guide
File: Create, Load a PDF File

File: Create, Load a PDF File

Home ›› XDoc.PDF ›› C# PDF: Create and Load PDF

C# PDF - PDF Creating in C#.NET

Tell Users How to Create New PDF File and Load PDF from Other Files


C#.NET PDF document file creating library control, RasterEdge XDoc.PDF SDK for .NET, is a robust & thread-safe .NET solution which provides a reliable and quick approach for C# developers to create a highly-secure and industry-standard PDF document file. The PDF document file created by RasterEdge C# PDF document creator library is searchable and can be fully populated with editable text and graphics programmatically.

This Visual C# .NET PDF document creation control toolkit can not only allow developers to generate standard PDF document file but also offer them the ability to count the page numbers of generated PDF document by simple C# programming code. As this PDF document creator library is built in .NET Framework 2.0 and designed specifically for .NET applications, C# developers can easily use this professional PDF document generating SDK in all .NET developing applications, including ASP.NET web services and Windows Forms application.

After creating a PDF document in C#.NET using this PDF document creating toolkit, if you need to add some text and draw some graphics on created PDF document file, you can also use this C#.NET PDF document drawing library control. Besides, using this PDF document metadata adding control, you can add some additional information to generated PDF file. What's more, you can also protect created PDF file by adding digital signature (watermark) on PDF using C# code.

Create PDF File with one Blank Page in C# Project

In C# class programming, you can use specific APIs to create PDF file. And the PDF document can contain one empty page or multiple empty pages. The following example will tell you how to create a PDF document with one empty page.

// Used to register all DLL assemblies.

// Create a blank PDF file.

Load PDF from Files Using C#

You may also load or create a PDF file from files like Word, Excel, PowerPoint, Tiff, Bmp, Jpeg, Png, Gif, etc. And in the following demo, Word (.docx) document is taking as an example.

// Used to register all DLL assemblies.

String inputFilePath = Program.RootPath + "\\" + "1.docx";
String outputFilePath = Program.RootPath + "\\" + "Output.pdf";

// Load a Word (.docx) document.
DOCXDocument doc = new DOCXDocument(inputFilePath);

// Convert it to PDF document.
doc.ConvertToDocument(DocumentType.PDF, outputFilePath);

Load PDF from Stream in C# Project

Certainly, PDF document can be loaded from stream in C# programming.

// Used to register all DLL assemblies.

// Load from a stream.
String inputFilePath2 = Program.RootPath + "\\" + "2.pdf";
using (FileStream fileStream = File.Open(inputFilePath2, FileMode.Open, FileAccess.Read))
    PDFDocument doc2 = new PDFDocument(fileStream);
if (doc2 == null) throw new Exception("fail to load PDF document from the stream");

    // ...