Click or drag to resize
Pdf Library for .NET
Getting Started

To start using Select.Pdf Library, follow the instructions from the Installation section to setup a project and add a reference to Select.Pdf.dll.

This section will show how to create a simple 'Hello World!' application with Select.Pdf.

Import the namespace

To use Select.Pdf classes, a namespace needs to be imported.

using SelectPdf;
Create the document

The first thing to do when using Select.Pdf library is to create the pdf document that is an instance of PdfDocument class.

// create a new pdf document
PdfDocument doc = new PdfDocument();
Create the first page of the document

Once the document is created, a first page is need in the pdf document. To do that, the method AddPage of the PdfDocument class can be used. A page in a pdf document is an instance of the PdfPage class.

// add a new page to the document
PdfPage page = doc.AddPage();
Create a font

To add a text to a pdf document, a font is needed. A font in a pdf document is an instance of the PdfFont class.

// create a new pdf font
PdfFont font = doc.AddFont(PdfStandardFont.Helvetica);
font.Size = 20;
Create a text element

To add a text to a pdf document, the PdfTextElement class can be used. After the PdfTextElement object is created, it must be added to the appropriate PdfPage object.

// create a new text element and add it to the page
PdfTextElement text = new PdfTextElement(50, 50, "Hello world!", font);
page.Add(text);
Save the document

Once the content is created, you can save the document. The document can be saved to a stream or file on disk.

// save pdf document
doc.Save(file);

// close pdf document
doc.Close();
Full Code

The full code of the 'Hello World!' application looks like this:

// create a new pdf document
PdfDocument doc = new PdfDocument();

// add a new page to the document
PdfPage page = doc.AddPage();

// create a new pdf font
PdfFont font = doc.AddFont(PdfStandardFont.Helvetica);
font.Size = 20;

// create a new text element and add it to the page
PdfTextElement text = new PdfTextElement(50, 50, "Hello world!", font);
page.Add(text);

// save pdf document
doc.Save(file);

// close pdf document
doc.Close();
See Also