Document
Overview
Document is a class in Aspose.PDF FOSS for .NET.
Inherits from: IDisposable.
Represents a PDF document.
This class provides 143 methods for working with Document objects in .NET programs.
Available methods include: AddEmbeddedFile, AddNamedDestination, BindXml, ChangePasswords, Check, Convert, ConvertPageToPNGMemoryStream, Create, Decrypt, Dispose, Document, Encrypt, and 40 additional methods.
All public members are accessible to any .NET application after installing the Aspose.PDF FOSS for .NET package.
Properties: Actions, AllowReusePageContent, Background, CenterWindow, Collection, CryptoAlgorithm, and 71 more.
Properties
| Name | Type | Access | Description |
|---|---|---|---|
IsLicensed | bool | Read | Whether a license is currently applied. |
JavaScript | JavaScriptCollection | Read | Document-level JavaScript (PDF spec §12.6.4.16 — /Names/JavaScript name tree in the catalog). |
Pages | PageCollection | Read | The collection of pages in this document. |
Info | DocumentInfo | Read | The document information dictionary (title, author, etc.). |
FileName | string? | Read | The file name/path this document was loaded from, or null if loaded from a stream. |
EnableObjectUnload | bool | Read/Write | Whether to unload large objects after use to reduce memory pressure. |
PdfVersion | string? | Read | The PDF version from the file header (e.g., “1.4”, “1.7”, “2.0”). |
PageCount | int | Read | Shortcut for Pages.Count. |
Version | string? | Read | Alias for PdfVersion. |
IsPdfaCompliant | bool | Read | True if the document declares itself PDF/A compliant. |
PdfFormat | Aspose.Pdf.PdfFormat | Read | Returns the PDF format declared by this document. |
IsLinearized | bool | Read/Write | Returns true if this PDF file is linearized (optimized for fast web viewing). |
EnableSignatureSanitization | bool | Read/Write | When true (default), the writer scrubs invalid signature references during save. |
_engineDoc | EngineDocFacade | Read | Engine handle exposed for the legacy doc._engineDoc.X access pattern. |
Form | Form | Read | The interactive form (AcroForm). |
HasForm | bool | Read | Whether the document has an interactive form. |
DisableFontLicenseVerifications | bool | Read/Write | Whether to disable font license verification checks. |
FontUtilities | IDocumentFontUtilities | Read | Font utilities for subsetting and font management. |
Outlines | OutlineCollection | Read | The document outline (bookmarks), or null if none exists. |
HasOutlines | bool | Read | Whether the document has bookmarks. |
Collection | Collection? | Read/Write | PDF Portfolio (collection) wrapper — returns the catalog’s Collection dictionary as a Collection, or null if the document is not a portfolio. |
Metadata | Metadata | Read | XMP metadata for the document. |
HasMetadata | bool | Read | Whether the document has XMP metadata. |
IsEncrypted | bool | Read | Whether the document is encrypted. |
IsDecrypted | bool | Read | Whether the document has been successfully decrypted (i.e., the decryptor was initialised). |
EncryptionInfo | EncryptionInfo? | Read | Encryption details, or null if not encrypted. |
Permissions | int | Read | Raw /P permissions bitmask from the encryption dictionary (PDF 32000-1:2008 Table 22). |
OpenAction | IAppointment? | Read/Write | The document open action (action or destination executed when opening the PDF), or null. |
PageInfo | PageInfo | Read/Write | Default page dimensions/margins applied to pages added after this is set. |
EmbeddedFiles | EmbeddedFileCollection | Read | Embedded files collection. |
HasEmbeddedFiles | bool | Read | Whether the document has embedded files. |
PageLabels | PageLabelCollection? | Read | Page labels, or null. |
HasPageLabels | bool | Read | Whether the document has page labels. |
HasCollection | bool | Read | Whether the document is a PDF Portfolio (has a /Collection dictionary in the catalog). |
OutputIntents | OutputIntents | Read | Output intents declared in the document catalog. |
Destinations | DestinationCollection | Read | Provides destination lookup methods (e.g., GetPageNumber by destination name). |
HasDestinations | bool | Read | Whether the document has named destinations. |
NamedDestinations | NamedDestinationCollection | Read | Named destinations in the document. |
OptionalContent | OptionalContentProperties? | Read | Optional content properties (layers), or null if none. |
HasLayers | bool | Read | Whether the document has optional content (layers). |
ViewerPreferences | ViewerPreferences? | Read | Viewer preferences that control how the document is displayed. |
CenterWindow | bool | Read/Write | /CenterWindow viewer preference: position document window in the centre of the screen. |
FitWindow | bool | Read/Write | /FitWindow viewer preference: resize the window to fit the first displayed page. |
DisplayDocTitle | bool | Read/Write | /DisplayDocTitle viewer preference: show the document title in the window’s title bar instead of the file name. |
PageLayoutName | string? | Read/Write | Raw /PageLayout name read from the catalog (e.g., “SinglePage”, “TwoColumnLeft”). |
PageModeName | string? | Read/Write | Raw /PageMode name read from the catalog (e.g., “UseNone”, “UseOutlines”). |
PageLayout | PageLayout | Read/Write | The /PageLayout entry as a typed enum. |
PageMode | PageMode | Read/Write | The /PageMode entry as a typed enum. |
NonFullScreenPageMode | PageMode | Read/Write | The /NonFullScreenPageMode viewer preference (which page mode to revert to when leaving full-screen). |
PrintScaling | PrintScaling | Read/Write | The /PrintScaling viewer preference. |
Duplex | PrintDuplex | Read/Write | The /Duplex viewer preference (default Simplex when unset). |
Direction | Direction | Read/Write | The /Direction viewer preference (text-flow direction). |
CryptoAlgorithm | CryptoAlgorithm? | Read | The encryption algorithm in use, or null when the document is not encrypted. |
Id | Id? | Read | The /ID array from the trailer, or null when no /ID entry is present. |
IsPdfUaCompliant | bool | Read | True when the document’s XMP metadata carries a pdfuaid:part entry (PDF/UA-1 identifier). |
Language | string? | Read/Write | The natural language of the document (BCP 47). |
IsTagged | bool | Read | Whether the document is tagged PDF. |
HasStructTree | bool | Read | Whether the document has a structure tree. |
StructTreeRoot | Aspose.Pdf.Tagged.StructTreeRoot? | Read | The structure-tree root (/StructTreeRoot) for reading a tagged document’s logical structure, or null when the document is not tagged. |
LogicalStructure | Aspose.Pdf.Structure.RootElement | Read | The root of the document’s logical-structure tree. |
TaggedContent | Tagged.ITaggedContent | Read | Tagged-content surface for accessibility metadata and the logical-structure tree. |
OptimizeSize | bool | Read/Write | Gets or sets a flag indicating whether the document should be optimized for size on save. |
EmbedStandardFonts | bool | Read/Write | When true, the standard 14 PostScript fonts (Helvetica / Times / Courier × 4 styles + Symbol + ZapfDingbats) are embedded into the saved document so the output renders identically without relying on viewer-side font fallbacks. |
IgnoreCorruptedObjects | bool | Read/Write | When true, the parser tolerates corrupted indirect-object declarations (extra/garbled bytes between objects) instead of throwing. |
Background | Color? | Read/Write | Document-wide background colour painted on every page before content during Save. |
Actions | Annotations.DocumentActionCollection | Read | Catalog /AA additional-action dictionary. |
CustomSecurityHandler | Security.ICustomSecurityHandler? | Read | Stored custom security handler when set via the ICustomSecurityHandler Encrypt overloads. |
AllowReusePageContent | bool | Read/Write | Whether the saver may reuse identical page-content streams. |
EnableNotificationLogging | bool | Read/Write | Whether the document emits notification log entries. |
HandleSignatureChange | bool | Read/Write | Whether signature fields fire change-handlers when their dict mutates. |
HideMenubar | bool | Read/Write | Viewer preference: hide the menu bar (/ViewerPreferences /HideMenubar). |
HideToolBar | bool | Read/Write | Viewer preference: hide the toolbar (/ViewerPreferences /HideToolbar). |
HideWindowUI | bool | Read/Write | Viewer preference: hide window UI chrome (/ViewerPreferences /HideWindowUI). |
IsXrefGapsAllowed | bool | Read/Write | Allow gaps in the xref table during parse. |
PickTrayByPdfSize | bool | Read/Write | Viewer preference: pick the paper tray by PDF page size (/ViewerPreferences /PickTrayByPDFSize). |
FileSizeLimitToMemoryLoading | int | Read/Write | Maximum file size (bytes) loaded entirely into memory. |
DefaultNodesNumInSubtrees | byte | Read | Default page-tree branching factor (PDF table 30 /Count vs /Kids ratio). |
Methods
| Signature | Description |
|---|---|
Document() | Create a new empty PDF document (parameterless constructor, matches public API). |
Document(filename: string) | Open a PDF document from a file path. |
Document(version: PdfVersion) | Create an empty document targeting the given PDF specification version. |
Document(filename: string, password: string) | Open an encrypted PDF document from a file path with a password. |
Document(filename: string, certOptions: Security.CertificateEncryptionOptions) | Open a Public-Key security-handler encrypted document from a file path using the supplied certificate-encryption options. |
Document(filename: string, certOptions: Security.CertificateEncryptionOptions, isManagedStream: bool) | File ctor with cert options and the isManagedStream flag (stored only — the in-memory byte buffer is always reusable). |
Document(input: Stream, certOptions: Security.CertificateEncryptionOptions) | Open a Public-Key security-handler encrypted document from a stream. |
Document(input: Stream, certOptions: Security.CertificateEncryptionOptions, isManagedStream: bool) | Stream ctor with cert options and the isManagedStream flag. |
Document(input: Stream, password: string) | Open an encrypted PDF document from a stream with a password. |
Document(path: string, options: HtmlLoadOptions) | Open an HTML file and convert to PDF using the given options. |
Document(stream: Stream, options: HtmlLoadOptions) | Open an HTML stream and convert to PDF using the given options. |
Create() | Create a new empty PDF document. |
Open(data: byte[]) | Open a PDF document from a byte array. |
Open(data: byte[], password: string) | Open an encrypted PDF document from a byte array with a password. |
Open(path: string) | Open a PDF document from a file path. |
Open(path: string, password: string) | Open an encrypted PDF document from a file path with a password. |
Document(input: Stream) | Open a PDF document from a stream (constructor, matches public API). |
Open(stream: Stream) | Open a PDF document from a stream. |
Open(stream: Stream, password: string) | Open an encrypted PDF document from a stream with a password. |
Open(path: string, options: Converters.MdLoadOptions) | Open a Markdown file and convert it to a PDF document. |
Open(data: byte[], options: Converters.MdLoadOptions) | Open a Markdown file from bytes and convert it to a PDF document. |
Open(path: string, options: Converters.SvgLoadOptions) | Open an SVG file and convert it to a PDF document. |
Open(path: string, options: HtmlLoadOptions) | Open an SVG file from bytes and convert it to a PDF document. |
Open(data: byte[], options: HtmlLoadOptions) | Open an HTML file from bytes and convert it to a PDF document. |
Open(data: byte[], options: Converters.SvgLoadOptions) | Calls Open on this Document instance. |
BindXml(file: string) | Bind an Aspose.Pdf XML template to this document. |
BindXml(stream: Stream) | Bind an Aspose.Pdf XML template from a stream to this document. |
BindXml(xmlStream: Stream, xslStream: Stream?) | Bind an Aspose.Pdf XML template from a stream with an optional XSLT stylesheet stream. |
BindXml(xmlStream: Stream, xslStream: Stream?, settings: System.Xml.XmlReaderSettings?) | Bind an Aspose.Pdf XML template from a stream with an optional XSLT stylesheet stream and explicit XmlReader settings for the input parse. |
BindXml(xmlFile: string, xslFile: string?) | Bind an Aspose.Pdf XML template with an optional XSLT stylesheet. |
Validate() | Validate the document structure and return any issues found. |
Validate(outputLogStream: Stream, format: PdfFormat) | Validate the document against a specific PDF format (PDF/A, PDF/X). |
Validate(options: PdfFormatConversionOptions) | Validate the document against a specific PDF format using conversion options. |
Validate(outputLogFileName: string, format: PdfFormat) | Validate the document against a specific PDF format, writing log to a file. |
GetPdfACompliance() | Returns the PDF/A compliance level detected from XMP metadata, or null if not a PDF/A document. |
IsRepairNeeded(options: RepairOptions) | Check whether the document needs repair. |
Repair() | Repair the document by re-serializing it. |
LinearizeDocument() | Linearize the document for fast web viewing. |
GetCatalogValue(key: string) | Reads a value from the document’s /Catalog by name. |
Flatten() | Flatten all form fields — renders their visual appearance into page content and removes the interactive form. |
Flatten(flattenSettings: Forms.Form.FlattenSettings) | Flatten with explicit settings. |
GetOrCreateMetadata() | Get or create XMP metadata for this document. |
AddEmbeddedFile(fileName: string, fileData: byte[], description: string?, mimeType: string?, compress: bool) | Add an embedded file to the document. |
AddNamedDestination(name: string, destination: DestinationArray) | Add a named destination to the document using the /Names → /Dests name tree. |
RemoveNamedDestination(name: string) | Remove a named destination from the document’s /Names → /Dests name tree. |
HasIncrementalUpdate() | Returns true if this PDF uses incremental updates (has multiple %%EOF markers). |
SetVersion(version: string) | Set the PDF version for the output header (e.g., “1.7”, “2.0”). |
ImportPage(source: Document, pageNumber: int, insertAt: int) | Import a single page from another document into this document. |
ImportPages(source: Document, pageNumbers: int[], insertAt: int) | Import specified pages from another document into this document. |
GetOrCreateViewerPreferences() | Get or create viewer preferences for this document. |
RemoveFormField(fieldName: string) | Remove a form field by name from all pages and the AcroForm. |
MergeDocuments(documents) | Calls MergeDocuments on this Document instance. |
MergeDocuments(files) | |
MergeDocuments(documents) | Merge every page of documents into a new destination Document. |
Merge(documents) | Merge every page of each documents entry into this document, preserving source order. |
Merge(files) | Merge every page of each file in files into this document. |
Merge(mergeOptions: MergeOptions, documents) | Merge with explicit options. |
Merge(mergeOptions: MergeOptions, files) | Merge files with explicit options — same semantics as the Document[] overload. |
MergeDocuments(mergeOptions: MergeOptions, files) | Static Merge: build a fresh Document containing every page from files, then apply mergeOptions. |
MergeDocuments(mergeOptions: MergeOptions, files) | Static Merge: file-paths variant. |
SendTo(device: Devices.DocumentDevice, output: Stream) | Render this document through device into output — delegates to Stream). |
SendTo(device: Devices.DocumentDevice, outputFileName: string) | File overload of DocumentDevice, Stream). |
SendTo(device: Devices.DocumentDevice, fromPage: int, toPage: int, output: Stream) | Render a page range — delegates to the device’s page-range Process overload. |
SendTo(device: Devices.DocumentDevice, fromPage: int, toPage: int, outputFileName: string) | File-pair page-range overload. |
Convert(fixup: Fixup, outputLog: Stream, onlyValidation: bool, parameters) | Run a pre-defined fixup operation. |
Convert(fixup: Fixup, outputLog: string, onlyValidation: bool, parameters) | File-log overload of Convert(Fixup, Stream, bool, object[]). |
Convert(fixup: Fixup, outputLog: string) | Apply fixup and write a log to outputLog (the common, non-validation case). |
Convert(srcFileName: string, loadOptions: LoadOptions, dstFileName: string, saveOptions: SaveOptions) | Open srcFileName via the load-options hierarchy (HtmlLoadOptions / SvgLoadOptions / MdLoadOptions all derive from LoadOptions) and save to dstFileName. |
Convert(srcFileName: string, loadOptions: LoadOptions, dstStream: Stream, saveOptions: SaveOptions) | Calls Convert on this Document instance. |
Convert(srcStream: Stream, loadOptions: LoadOptions, dstFileName: string, saveOptions: SaveOptions) | |
Convert(srcStream: Stream, loadOptions: LoadOptions, dstStream: Stream, saveOptions: SaveOptions) | |
Encrypt(userPassword: string, ownerPassword: string, permissions: DocumentPrivilege?, algorithm: CryptoAlgorithm) | Encrypt the document with the specified algorithm, passwords, and permissions. |
Encrypt(userPassword: string, ownerPassword: string, privileges: DocumentPrivilege?, cryptoAlgorithm: CryptoAlgorithm, usePdf20: bool) | Encrypt overload accepting an explicit usePdf20 flag. |
Encrypt(userPassword: string, ownerPassword: string, permissions: Aspose.Pdf.Permissions, cryptoAlgorithm: CryptoAlgorithm, usePdf20: bool) | Encrypt overload accepting the Permissions flags enum and an explicit usePdf20 flag. |
Encrypt(userPassword: string, ownerPassword: string, permissions: Aspose.Pdf.Permissions, cryptoAlgorithm: CryptoAlgorithm) | Encrypt overload accepting the legacy Permissions flags enum. |
ChangePasswords(ownerPassword: string, newUserPassword: string, newOwnerPassword: string) | Change the password on the bound document. |
Decrypt() | Remove encryption from the document. |
Optimize() | Optimize document resources by removing unused objects and deduplicating streams. |
ProcessParagraphs() | Process paragraphs in the document (layout step before save). |
OptimizeResources() | Calls OptimizeResources on this Document instance. |
OptimizeResources(strategy: Aspose.Pdf.Optimization.OptimizationOptions) | |
Convert(options: PdfFormatConversionOptions) | Convert the document to the specified PDF/A conformance level. |
Convert(outputLogFileName: string, format: PdfFormat, action: ConvertErrorAction) | Convert the document to a specific PDF/A format with a log file. |
Convert(outputLogFileName: string, format: PdfFormat, action: ConvertErrorAction, transparencyAction: ConvertTransparencyAction) | Convert the document to a specific PDF/A format with a log file, specifying transparency handling. |
Convert(outputLogStream: Stream, format: PdfFormat, action: ConvertErrorAction) | Convert the document to a specific PDF/A format with a log stream. |
Convert(outputLogStream: Stream, format: PdfFormat, action: ConvertErrorAction, transparencyAction: ConvertTransparencyAction) | Stream-log overload with explicit transparency action. |
RemovePdfaCompliance() | Remove PDF/A compliance identification from XMP metadata. |
Save() | Save the document in-place: writes back to the file the document was opened from (FileName), or performs an incremental save to the original source stream when the document was opened from a writable FileStream. |
ToArray() | Serialize the document into a fresh byte array. |
Encrypt(userPassword: string, ownerPassword: string, privileges: Facades.DocumentPrivilege, customHandler: Security.ICustomSecurityHandler) | Encrypt with a custom security handler. |
Encrypt(userPassword: string, ownerPassword: string, permissions: Aspose.Pdf.Permissions, customHandler: Security.ICustomSecurityHandler) | Same — Permissions-typed overload. |
Encrypt(permissions: Aspose.Pdf.Permissions, cryptoAlgorithm: CryptoAlgorithm, publicCertificates: System.Collections.Generic.IList<System.Security.Cryptography.X509Certificates.X509Certificate2>) | Encrypt with a list of recipient public certificates (Public-Key /Filter security handler). |
Save(outputFileName: string) | Save the document to a file. |
Save(outputFileName: string, format: SaveFormat) | Save the document to a file in the specified format. |
Save(outputStream: Stream, format: SaveFormat) | Save the document to a stream in the specified format. |
Save(output: Stream, options: HtmlSaveOptions) | Save the document as HTML to a stream using the specified options. |
Save(path: string, options: HtmlSaveOptions) | Save the document as HTML to a file using the specified options. |
Save(outputStream: Stream, options: SaveOptions) | Save to a stream using general SaveOptions (stub type from Aspose.Pdf namespace). |
Save(outputFileName: string, options: SaveOptions) | Save to a file using general SaveOptions (stub type from Aspose.Pdf namespace). |
Save(options: SaveOptions) | Save the document using the configured SaveOptions. |
SaveAsync(cancellationToken: System.Threading.CancellationToken) | Async wrapper around Save(). |
SaveAsync(options: SaveOptions, cancellationToken: System.Threading.CancellationToken) | Async wrapper around Save(SaveOptions). |
SaveAsync(output: Stream, cancellationToken: System.Threading.CancellationToken) | Async wrapper around Save(Stream). |
SaveAsync(outputStream: Stream, format: SaveFormat, cancellationToken: System.Threading.CancellationToken) | Async wrapper around Save(Stream, SaveFormat). |
SaveAsync(outputStream: Stream, options: SaveOptions, cancellationToken: System.Threading.CancellationToken) | Async wrapper around Save(Stream, SaveOptions). |
SaveAsync(outputFileName: string, cancellationToken: System.Threading.CancellationToken) | Async wrapper around Save(string). |
SaveAsync(outputFileName: string, format: SaveFormat, cancellationToken: System.Threading.CancellationToken) | Async wrapper around Save(string, SaveFormat). |
SaveAsync(outputFileName: string, options: SaveOptions, cancellationToken: System.Threading.CancellationToken) | Async wrapper around Save(string, SaveOptions). |
Save(output: Stream) | Save the document to a stream. |
SetDefaultFileSizeLimitToMemoryLoading() | Reset FileSizeLimitToMemoryLoading to its built-in default. |
SetTitle(title: string) | Update the /Info /Title entry. |
PageNodesToBalancedTree(nodesNumInSubtrees: byte) | Rebuild the page tree so each subtree has nodesNumInSubtrees children. |
RemoveMetadata() | Remove all metadata. |
RemovePdfUaCompliance() | Remove PDF/UA compliance markers. |
FlattenTransparency() | Flatten transparency to opaque graphics. |
Repair(options: RepairOptions) | Apply the requested repair pass. |
GetObjectById(id: string) | Resolve a PDF object by string id. |
ExportAnnotationsToXfdf(stream: Stream) | Export every annotation in the document to an XFDF stream. |
ExportAnnotationsToXfdf(fileName: string) | Export every annotation in the document to an XFDF file. |
ImportAnnotationsFromXfdf(stream: Stream) | Import annotations from an XFDF stream into the document. |
ImportAnnotationsFromXfdf(fileName: string) | Import annotations from an XFDF file into the document. |
GetXmpMetadata(stream: Stream) | Write the document’s XMP /Metadata packet to stream. |
SetXmpMetadata(stream: Stream) | Replace the document’s XMP /Metadata packet from stream. |
ConvertPageToPNGMemoryStream(page: Page) | Convert one page to a PNG memory stream. |
SaveXml(file: string) | Save document as XML (Aspose-Pdf XML schema). |
Check(doRepair: bool) | Validate / repair the document. |
LoadFrom(filename: string, options: LoadOptions) | Async file load wrapper (currently synchronous). |
Document(filename: string, isManagedStream: bool) | Single-arg ctor named filename. |
Document(input: Stream, isManagedStream: bool) | Stream ctor with managed-stream flag. |
Document(input: Stream, password: string, isManagedStream: bool) | Stream ctor with password + managed-stream flag. |
Document(filename: string, password: string, isManagedStream: bool) | File ctor with password + managed-stream flag. |
Document(input: Stream, password: string, customSecurityHandler: Aspose.Pdf.Security.ICustomSecurityHandler) | Stream ctor with password + ICustomSecurityHandler. |
Document(input: Stream, password: string, isManagedStream: bool, customSecurityHandler: Aspose.Pdf.Security.ICustomSecurityHandler) | Stream ctor with password + managed-stream + ICustomSecurityHandler. |
Document(filename: string, password: string, customSecurityHandler: Aspose.Pdf.Security.ICustomSecurityHandler) | File ctor with password + ICustomSecurityHandler. |
Document(filename: string, password: string, isManagedStream: bool, customSecurityHandler: Aspose.Pdf.Security.ICustomSecurityHandler) | File ctor with password + managed-stream + ICustomSecurityHandler. |
Document(input: Stream, options: LoadOptions) | Stream ctor with LoadOptions. |
Document(filename: string, options: LoadOptions) | File ctor with LoadOptions. |
FreeMemory() | Clears memory. |
Dispose() | Calls Dispose on this Document instance. |
Convert(callback: CallBackGetHocr, flattenImages: bool) | Render each page to an image, hand it to the OCR callback, then overlay the returned hOCR text on the page as an invisible text layer (text rendering mode 3, /Tr 3) so the PDF becomes searchable / copy-pasteable. |
Convert(callback: CallBackGetHocrWithPage, flattenImages: bool) | |
Convert(callback: CallBackGetHocr) | Convenience overload: same as Convert(CallBackGetHocr, bool) with flattenImages = false. |
Convert(callback: CallBackGetHocrWithPage) | Convenience overload of Convert(CallBackGetHocrWithPage, bool) with flattenImages = false. |