Creating a Document

The fundamental class for creating all PDF documents using the DynamicPDF Core Suite for .NET is the Document class.

The Document class is for creating PDF documents while the MergeDocument class is for modifying existing PDF documents.

Creating a PDF document from scratch always begins with the the Document class. You can set metadata properties, viewer preferences, and add pages and templates via the Document class. You also set document security, create user events, and other metadata such as XMP metadata.

PDF Document Metadata Properties

When creating a PDF you can set the following metadata properties. These properties are then displayed in the PDF reader software.

Property Use
Author The document's author.
Creator The document's creator.
Keywords The document's keywords.
Producer The document's producer.
Subject The document's subject.
Title The document's title.

Other properties include properties related to a document's appearance in a PDF viewer, security, and other properties. Refer to the API documentation for a complete list of properties (Document).

Configuration

You can set configuration to a Document programmatically or through a configuration file. Configuration values include values for specifying if the document is linearized or not and the PDF version. Refer to the Configuration documentation for more information.

Document Output

After constructing a PDF document, you output the document using the Document classes' Draw method. The method is overloaded to output to a stream, byte array, file, or ASPX page. Refer to the Document Output documentation topic for more information.

Example

The following simple example creates a simple one-page document and writes the results to a file.

A document must have at lease one page or an error is thrown.

Document document = new Document();

Page page = new Page(PageSize.Letter, PageOrientation.Portrait, 54.0f);
document.Pages.Add(page);
            
string labelText = "Hello World...\nFrom DynamicPDF Core Suite for .NET\nDynamicPDF.com";

Label label = new Label(labelText, 0, 0, 504, 100,   Font.Helvetica, 18, TextAlign.Center);

page.Elements.Add(label);
document.Draw(outputPath);
Dim document As New Document()
Dim page As New Page(PageSize.Letter, PageOrientation.Portrait, 54.0F)

document.Pages.Add(page)

Dim labelText As String = "Hello World..." & vbLf & "From DynamicPDF Core Suite for .NET" & vbLf & "DynamicPDF.com"
Dim label As New Label(labelText, 0, 0, 504, 100, Font.Helvetica, 18, TextAlign.Center)
page.Elements.Add(label)
document.Draw(outputPath)

Figure 1. A simple PDF document.

In this topic