Class PdfDocument
Represents a PDF document.
public sealed class PdfDocument
- Inheritance
-
objectPdfDocument
Constructors
- PdfDocument()
Creates a new PDF document in memory. To open an existing PDF file, use the PdfReader class.
- PdfDocument(Stream)
Creates a new PDF document using the specified stream. The stream won’t be used until the document is closed. At that time the document is saved automatically. Do not call Save for documents created with this constructor, just call Close. To open an existing PDF file, use the PdfReader class.
- PdfDocument(string)
Creates a new PDF document with the specified file name. The file is immediately created and kept locked until the document is closed. At that time the document is saved automatically. Do not call Save for documents created with this constructor, just call Close. To open an existing PDF file and import it, use the PdfReader class.
Properties
- AcroForm
Get the AcroForm (interactive form) dictionary.
- Catalog
Gets the PdfCatalog of the current document.
- CustomValues
This function is intended to be undocumented.
- Events
Encapsulates the document’s events.
- FileSize
Gets the file size of the document.
- FullPath
Gets the full qualified file name if the document was read form a file, or an empty string otherwise.
- Guid
Gets a Guid that uniquely identifies this instance of PdfDocument.
- Info
Gets information about the document.
- Internals
Gets the PdfInternals object of this document, that grants access to some internal structures which are not part of the public interface of PdfDocument.
- IsImported
Returns a value indicating whether the document was newly created or opened from an existing document. Returns true if the document was opened with the PdfReader.Open function, false otherwise.
- IsPdfA
Gets a value indicating that you create a PDF/A conform document. This function is temporary and will change in the future.
- IsReadOnly
Returns a value indicating whether the document is read only or can be modified.
- Language
Gets or sets the default language of the document.
- Options
Gets the document options used for saving the document.
- Outlines
Gets the root of the outline (or bookmark) tree.
- PageCount
Gets the number of pages in the document.
- PageLayout
Gets or sets a value specifying the page layout to be used when the document is opened.
- PageMode
Gets or sets a value specifying how the document should be displayed when opened.
- Pages
Get the pages dictionary.
- RenderEvents
Encapsulates the document’s render events.
- SecurityHandler
Gets the standard security handler and creates it, if not existing.
- SecuritySettings
Gets the security settings of this document.
- Settings
Gets PDF specific document settings.
- Tag
Gets or sets a user-defined object that contains arbitrary information associated with this document. The tag is not used by PDFsharp.
- Version
Gets or sets the PDF version number as integer. Return value 14 e.g. means PDF 1.4 / Acrobat 5 etc.
- ViewerPreferences
Gets the viewer preferences of this document.
Methods
- AddCharacters(XFont, string)
Adds characters whose glyphs have to be embedded in the PDF file. By default, PDFsharp only embeds glyphs of a font that are used for drawing text on a page. With this function actually unused glyphs can be added. This is useful for PDF that can be modified or has text fields. So all characters that can be potentially used are available in the PDF document.
- AddEmbeddedFile(string, Stream)
This function is deprecated. TODO Adds an embedded file to the document.
- AddEmbeddedFile(string, string)
Adds an embedded file to the document.
- AddNamedDestination(string, int, PdfNamedDestinationParameters)
Adds a named destination to the document.
- AddPage()
Creates a new page and adds it to this document. Depending on the IsMetric property of the current region the page size is set to A4 or Letter respectively. If this size is not appropriate it should be changed before any drawing operations are performed on the page.
- AddPage(PdfPage)
Adds the specified page to this document. If the page is from an external document, it is imported to this document. In this case the returned page is not the same object as the specified one.
- AppendPages(PdfDocument)
Appends all pages of a document opened with Import, with their form fields, bookmarks and links. See AppendPages(PdfDocument, int, int, PdfPageImportOptions).
- AppendPages(PdfDocument, PdfPageImportOptions)
Appends all pages of a document opened with Import, with their form fields, bookmarks and links. See AppendPages(PdfDocument, int, int, PdfPageImportOptions).
- AppendPages(PdfDocument, int, int)
Appends pages of a document opened with Import, with their form fields, bookmarks and links. See AppendPages(PdfDocument, int, int, PdfPageImportOptions).
- AppendPages(PdfDocument, int, int, PdfPageImportOptions)
Appends pages of a document opened with Import, with their form fields, bookmarks and links, for merging documents. Unlike AddPage(PdfPage):
- Form fields with a widget on an appended page are added to this document's form, so they can be filled or flattened, with the font, size and colour their own form gave them. A field whose name this document already uses is renamed name_2, name_3 and so on; RenamedFields lists the new names.
- Links, the GoTo actions of buttons and other annotations, and bookmarks lead to the appended pages. Named destinations are written as the explicit destinations they name. A link to a page that is not appended is removed, as is such an action; a bookmark to such a page is removed unless it holds bookmarks that are kept. Links and bookmarks that lead elsewhere, such as a web address, are kept.
- Annotations do not pull in hidden copies of other pages.
Append a source in one call: pages appended in separate calls are separate copies, so a field with widgets in both becomes two fields, and links and bookmarks between them are removed. Not carried: the structure tree (tags), page labels, optional content (layers) settings, named destinations as names, XFA, and fields without a widget on an appended page. Signatures are copied as they are; they cannot be valid in the new file. Nothing is changed if the arguments are refused, and a failure while copying from a damaged source leaves this document's pages, form and bookmarks as they were.
- CanSave(ref string)
Determines whether the document can be saved.
- Close()
Closes this instance. Saves the document if the PdfDocument was created with a filename or a stream.
- Dispose()
Disposes all references to this document stored in other documents. This function should be called for documents you finished importing pages from. Calling Dispose is technically not necessary but useful for earlier reclaiming memory of documents you do not need anymore.
- ExtractPages(int, int)
Creates a new document from pages of this document, which must be opened with Import, with their form fields, bookmarks and links, for splitting a document. See AppendPages(PdfDocument, int, int, PdfPageImportOptions) for what comes along.
- ExtractPages(int, int, PdfPageImportOptions)
Creates a new document from pages of this document, which must be opened with Import, with their form fields, bookmarks and links, for splitting a document. See AppendPages(PdfDocument, int, int, PdfPageImportOptions) for what comes along.
- ~PdfDocument()
Why we need XML documentation here?
- Flatten()
Flattens the document's form: draws every visible form field into its page as it currently appears, then removes the fields, so the values can no longer be edited or read as form data. Text and choice fields without an up-to-date appearance get one drawn first; if a value cannot be drawn (no usable font in the form's resources), an System.InvalidOperationException is thrown and the document is not changed. Annotations other than form fields are kept. A document without a form is left as it is. (PDFsharp 6.2.4 only marked the top-level fields read-only; FreePDF 7.0 threw.)
- InsertPage(int)
Creates a new page and inserts it in this document at the specified position.
- InsertPage(int, PdfPage)
Inserts the specified page in this document. If the page is from an external document, it is imported to this document. In this case the returned page is not the same object as the specified one.
- Save(Stream, bool)
Saves the document to the specified stream.
- Save(string)
Saves the document to the specified path. If a file already exists, it will be overwritten.
- SaveAsync(Stream, bool)
Saves the document to the specified stream. The async version of save is useful if you want to create a signed PDF file with a time stamp. A time stamp server should be accessed asynchronously, and therefore we introduced this function.
- SaveAsync(string)
Saves the document async to the specified path. If a file already exists, it will be overwritten. The async version of save is useful if you want to create a signed PDF file with a time stamp. A time stamp server should be accessed asynchronously, and therefore we introduced this function.
- SetPdfA(PdfAFormat)
Sets PDF/A part and conformance level for the document. After once set it cannot be changed.
- SetRequiredVersion(int)
Adjusts the version if the current version is lower than the required version. Version is not adjusted for inconsistent files in ReadOnly mode.