 |
PdfDocument Class |
Represents a PDF document. Can be used to create a new empty PDF document or to load an existing one.
Inheritance HierarchySystemObject
SelectPdf.UniversalPdfDocument
Namespace: SelectPdf.UniversalAssembly: SelectPdf.HtmlToPdf.Universal (in SelectPdf.HtmlToPdf.Universal.dll) Version: 26.4
SyntaxThe PdfDocument type exposes the following members.
Constructors| | Name | Description |
|---|
 | PdfDocument |
Initializes a new instance of the PdfDocument class, creating an empty PDF document.
|
  | PdfDocument(PdfStandard) |
Creates an empty PDF document that conforms to the specified PDF standard — use this
when you want from-scratch output to be PDF/A (archival) or PDF/X (print exchange)
compliant. Equivalent to PdfDocument when
pdfStandard is Full.
|
Top
Properties| | Name | Description |
|---|
 | Bookmarks |
Gets the document-level bookmark (outline) collection. Use this to add
navigation entries that appear in the PDF reader's outline pane.
|
 | CompressionLevel |
Gets or sets the Flate/DEFLATE compression level applied to content streams, fonts,
and non-image objects in the PDF. Complements JpegCompressionEnabled,
which handles image XObjects. Default is Normal.
|
 | DocumentInformation |
Gets the document information properties (title, author, subject, etc.).
|
 | Fonts |
Gets the document-level font collection. Use doc.Fonts.Add(...) to register
fonts (standard, CJK, or embedded TrueType) that can be retrieved later by index
and reused across PdfTextElement instances. For PDF/A output from
scratch, add a TrueType font via Add(String) or
Add(Byte) — the 14 built-in
PdfStandardFont values are not allowed under PDF/A and will
throw a PdfDocumentException when used.
|
 | Footer |
Gets or sets the template repeated at the bottom of every page of the pdf document.
|
 | Header |
Gets or sets the template repeated at the top of every page of the pdf document.
|
 | JpegCompressionEnabled |
Gets or sets a flag indicating if JPEG compression is applied to the images in the
generated pdf document. Default is true.
|
 | JpegCompressionLevel |
Gets or sets the JPEG compression level for images in the generated pdf document.
Value range: 0 (lowest compression, best quality) to 100 (highest compression, worst quality).
Only effective when JpegCompressionEnabled is true. Default is 10.
|
 | Language |
Gets or sets the natural language of the document content (for example "en-US"), written as
the document /Lang entry. Required for accessible / PDF/UA output.
|
 | LFN |
Gets or sets the path of the diagnostic log file written while html content is rendered
into this document. It is passed to the html elements added to the document's pages, and
to the templates obtained through AddTemplate(Single, Single),
Header and Footer. A template or html element that has a log
file of its own keeps it. When none is set, no log is written.
|
 | Margins |
The default pdf document margins. New pages will use the default margins if no
margins are specified when the page is added.
|
 | Pages |
Gets the collection of pages in the document.
|
 | Security |
Gets the security settings of the document.
|
 | Templates |
Gets the collection of reusable templates of the document. A template is repeated on more than
one page (headers, footers, watermarks, page numbers). Routed onto the document at save time.
|
 | Title |
Gets or sets the document title. For a tagged document this is written as the title
metadata and, together with DisplayDocTitle, is required
for PDF/UA conformance.
|
 | ViewerPreferences |
Gets the viewer-preferences block that controls how the document appears in
a pdf reader — which panel opens (bookmarks, thumbnails, full-screen), whether
the reader's tool bar / menu bar / window UI is hidden, whether the window
resizes to the first page, and so on. Mutations write through to the underlying
PDF immediately. Works on every document origin — newly-created documents,
loaded documents, and HtmlToPdf output.
For the HtmlToPdf pipeline, ViewerPreferences is
the pre-conversion knob; the two are complementary — set options before
conversion, then fine-tune the returned document via this property.
|
Top
Methods| | Name | Description |
|---|
 | AddAssociatedFile(String, PdfAttachmentRelationship, String, String) |
Embeds a file from disk into the document as an associated file.
|
 | AddAssociatedFile(Stream, String, PdfAttachmentRelationship, String, String) |
Embeds the content of a stream into the document as an associated file.
|
 | AddBookmark(String, PdfDestination) |
Adds a new bookmark to the document outline. Shorthand for
doc.Bookmarks.Add(text, destination).
|
 | AddBookmark(String, PdfDestination, PdfBookmark) |
Adds a new bookmark as a child of the specified parent bookmark. Shorthand for
parent.ChildNodes.Add(text, destination).
|
 | AddFont(PdfStandardCJKFont) |
Adds one of the standard CJK pdf fonts to the pdf document.
|
 | AddFont(PdfStandardFont) |
Adds one of the standard pdf fonts to the pdf document.
|
 | AddFont(PdfSystemFont) |
Adds a system font to the pdf document. The font is always embedded.
|
 | AddFont(String) |
Adds a font loaded from a TrueType / OpenType file to the pdf document.
|
 | AddFont(PdfSystemFont, Boolean) |
Adds a system font to the pdf document.
|
  | AddPage |
Adds a new page to the document. Shorthand for Add.
|
 | AddPage(PdfMargins) |
Adds a new page with the specified margins.
|
 | AddPage(PdfPage) |
Adds an existing PdfPage (for example, from another document) to this document.
|
 | AddPage(PdfCustomPageSize, PdfMargins) |
Adds a new page with the specified size and margins.
|
 | AddPage(PdfCustomPageSize, PdfMargins, PdfPageOrientation) |
Adds a new page with the specified size, margins, and orientation.
|
 | AddTemplate(RectangleF) |
Creates a template with the specified bounds and adds it to the pdf document.
|
 | AddTemplate(Single, Single) |
Creates a template with the specified dimensions and adds it to the pdf document.
|
  | Append(PdfDocument) |
Appends all pages from another PDF document to this document.
The appended document must remain open until this document is saved.
|
 | Append(Stream) |
Appends all pages from a PDF stream to this document.
|
 | Append(String) |
Appends all pages from a PDF file to this document.
|
 | Close |
Closes the document and releases all resources.
|
 | Close(Boolean) |
Closes the document. When completely is true, all resources are released.
|
 | DetachStream |
Detaches the stream associated with the document.
|
  | GetPagesCount(Stream) |
Gets the number of pages in a PDF document loaded from a stream.
|
  | GetPagesCount(String) |
Gets the number of pages in a PDF file without fully loading the document.
|
 | InsertPage(Int32, PdfPage) |
Inserts an existing PdfPage at the specified index in this document.
|
 | InsertPage(Int32, PdfCustomPageSize, PdfMargins, PdfPageOrientation) |
Creates a new page and inserts it at the specified index with the given size, margins, and orientation.
|
 | RemovePage |
Removes the specified page from the document.
|
 | RemovePageAt |
Removes the page at the specified index.
|
 | Save |
Saves the PDF document and returns the content as a byte array.
|
 | Save(Stream) |
Saves the PDF document to a stream.
|
  | Save(String) |
Saves the PDF document to a file.
|
Top
ExamplePdfDocument document = new PdfDocument();
PdfPage page = document.AddPage();
document.DocumentInformation.Title = "Report";
document.Save("out.pdf");
document.Close();Dim document As New PdfDocument()
Dim page As PdfPage = document.AddPage()
document.DocumentInformation.Title = "Report"
document.Save("out.pdf")
document.Close()
See Also