Class PdfDocument
- Namespace
- SoftZenPdf
- Assembly
- SoftZenPdf.dll
A PDF document under construction: add pages, draw on them, set metadata, bookmarks, forms, watermarks or encryption, then Save(string) it. Existing PDFs are read with PdfReader and can be recombined with Merge(params PdfReader[]), Extract(PdfReader, IEnumerable<int>) and ImportPages(PdfReader).
public sealed class PdfDocument
- Inheritance
-
PdfDocument
- Inherited Members
Examples
var document = new PdfDocument();
var page = document.AddPage(PageSize.A4);
page.Content.DrawText("Hello, SoftZenPdf", 72, 770, StandardFont.Helvetica, 24);
document.Save("hello.pdf");
Remarks
Coordinates are in PDF user space: points (1/72 inch) with the origin at the bottom-left corner of the page. The whole document is kept in memory until it is saved. Instances are not thread-safe.
Constructors
- PdfDocument()
Creates an empty document with no pages.
Properties
- CatalogReference
Reference to the document catalog, the root object of the file (ISO 32000-1 §7.7.2).
- CompressContent
Whether page content streams are Flate-compressed when the document is saved. Defaults to true; turn it off to inspect content streams in a text editor.
- Conformance
The PDF/A conformance level this document was created for, or null for an ordinary document. Set by CreateForPdfA(PdfAConformance).
- DefaultPageSize
The size of pages added with AddPage(PageSize?, PageOrientation?) when no size is passed. Defaults to A4. Changing it does not affect pages already added, or imported pages, which keep their own size.
- Form
The interactive form (AcroForm) that holds the fields added with the
PdfPage.Add…Fieldmethods.
- Info
Document information (title, author, dates and so on), written to the Info dictionary and to XMP metadata.
- IsEncrypted
Whether Encrypt(string?, string?, PdfPermissions, PdfEncryptionAlgorithm) has been called (and not undone by RemoveEncryption()).
- Objects
Every indirect object added so far, in object-number order. This is a low-level view; most code only needs Pages.
- Outline
The document outline (bookmarks) shown in a viewer's navigation pane.
- PageTreeReference
Reference to the root of the page tree.
- Pages
The pages of the document, in display order.
- ValidateOnSave
For PDF/A documents, whether Save(Stream) validates the output first and throws PdfAException if it finds violations. Defaults to true. Ignored for ordinary documents.
- Watermark
A watermark drawn over every page when the document is saved, including imported pages, or null for none.
- WriteXmpMetadata
Whether Info is also written as an XMP metadata stream. Defaults to true.
Methods
- AddImagePage(PdfImage, ImagePageOptions?)
Appends a page that shows one image, sized and placed as
optionsdescribe.
- AddObject(PdfObject)
Adds a low-level object to the file as a new indirect object. Only needed when building PDF structures by hand.
- AddPage(PageSize?, PageOrientation?)
Appends a new, empty page.
- ConformsToPdfA2b()
Returns true if ValidatePdfA2b() finds no violations.
- CreateForPdfA(PdfAConformance)
Creates an empty document in PDF/A mode. Such documents refuse features that PDF/A forbids (standard 14 fonts, encryption, form fields, CMYK images), get an sRGB output intent and PDF/A XMP identification, and are validated on save.
- Encrypt(string?, string?, PdfPermissions, PdfEncryptionAlgorithm)
Encrypts the document with the Standard Security Handler when it is saved.
- Extract(PdfReader, IEnumerable<int>)
Creates a new document from selected pages of
source, in the order given.
- FromImages(IEnumerable<string>, ImagePageOptions?)
Creates a document with a page for each image: one page per image file, and one per page of a multi-page TIFF.
- ImportPages(PdfReader)
Appends copies of every page of
source.
- ImportPages(PdfReader, IEnumerable<int>)
Appends copies of selected pages of
source, in the order given.
- Merge(params PdfReader[])
Creates a new document containing every page of each source, in order.
- MovePage(int, int)
Moves a page to a new position; the pages in between shift by one.
- RemoveEncryption()
Cancels a previous Encrypt(string?, string?, PdfPermissions, PdfEncryptionAlgorithm) call, so the document is saved unencrypted.
- Save(Stream)
Writes the document to a stream. The stream is not closed.
- Save(string)
Writes the document to a file, replacing it if it exists.
- ToArray()
Saves the document into a new byte array, for example to return it from a web endpoint.
- ValidatePdfA2b()
Renders the document in memory and checks it against SoftZenPdf's PDF/A-2b rules (a practical subset of ISO 19005-2, not a replacement for veraPDF).