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

NameTypeAccessDescription
IsLicensedboolReadWhether a license is currently applied.
JavaScriptJavaScriptCollectionReadDocument-level JavaScript (PDF spec §12.6.4.16 — /Names/JavaScript name tree in the catalog).
PagesPageCollectionReadThe collection of pages in this document.
InfoDocumentInfoReadThe document information dictionary (title, author, etc.).
FileNamestring?ReadThe file name/path this document was loaded from, or null if loaded from a stream.
EnableObjectUnloadboolRead/WriteWhether to unload large objects after use to reduce memory pressure.
PdfVersionstring?ReadThe PDF version from the file header (e.g., “1.4”, “1.7”, “2.0”).
PageCountintReadShortcut for Pages.Count.
Versionstring?ReadAlias for PdfVersion.
IsPdfaCompliantboolReadTrue if the document declares itself PDF/A compliant.
PdfFormatAspose.Pdf.PdfFormatReadReturns the PDF format declared by this document.
IsLinearizedboolRead/WriteReturns true if this PDF file is linearized (optimized for fast web viewing).
EnableSignatureSanitizationboolRead/WriteWhen true (default), the writer scrubs invalid signature references during save.
_engineDocEngineDocFacadeReadEngine handle exposed for the legacy doc._engineDoc.X access pattern.
FormFormReadThe interactive form (AcroForm).
HasFormboolReadWhether the document has an interactive form.
DisableFontLicenseVerificationsboolRead/WriteWhether to disable font license verification checks.
FontUtilitiesIDocumentFontUtilitiesReadFont utilities for subsetting and font management.
OutlinesOutlineCollectionReadThe document outline (bookmarks), or null if none exists.
HasOutlinesboolReadWhether the document has bookmarks.
CollectionCollection?Read/WritePDF Portfolio (collection) wrapper — returns the catalog’s Collection dictionary as a Collection, or null if the document is not a portfolio.
MetadataMetadataReadXMP metadata for the document.
HasMetadataboolReadWhether the document has XMP metadata.
IsEncryptedboolReadWhether the document is encrypted.
IsDecryptedboolReadWhether the document has been successfully decrypted (i.e., the decryptor was initialised).
EncryptionInfoEncryptionInfo?ReadEncryption details, or null if not encrypted.
PermissionsintReadRaw /P permissions bitmask from the encryption dictionary (PDF 32000-1:2008 Table 22).
OpenActionIAppointment?Read/WriteThe document open action (action or destination executed when opening the PDF), or null.
PageInfoPageInfoRead/WriteDefault page dimensions/margins applied to pages added after this is set.
EmbeddedFilesEmbeddedFileCollectionReadEmbedded files collection.
HasEmbeddedFilesboolReadWhether the document has embedded files.
PageLabelsPageLabelCollection?ReadPage labels, or null.
HasPageLabelsboolReadWhether the document has page labels.
HasCollectionboolReadWhether the document is a PDF Portfolio (has a /Collection dictionary in the catalog).
OutputIntentsOutputIntentsReadOutput intents declared in the document catalog.
DestinationsDestinationCollectionReadProvides destination lookup methods (e.g., GetPageNumber by destination name).
HasDestinationsboolReadWhether the document has named destinations.
NamedDestinationsNamedDestinationCollectionReadNamed destinations in the document.
OptionalContentOptionalContentProperties?ReadOptional content properties (layers), or null if none.
HasLayersboolReadWhether the document has optional content (layers).
ViewerPreferencesViewerPreferences?ReadViewer preferences that control how the document is displayed.
CenterWindowboolRead/Write/CenterWindow viewer preference: position document window in the centre of the screen.
FitWindowboolRead/Write/FitWindow viewer preference: resize the window to fit the first displayed page.
DisplayDocTitleboolRead/Write/DisplayDocTitle viewer preference: show the document title in the window’s title bar instead of the file name.
PageLayoutNamestring?Read/WriteRaw /PageLayout name read from the catalog (e.g., “SinglePage”, “TwoColumnLeft”).
PageModeNamestring?Read/WriteRaw /PageMode name read from the catalog (e.g., “UseNone”, “UseOutlines”).
PageLayoutPageLayoutRead/WriteThe /PageLayout entry as a typed enum.
PageModePageModeRead/WriteThe /PageMode entry as a typed enum.
NonFullScreenPageModePageModeRead/WriteThe /NonFullScreenPageMode viewer preference (which page mode to revert to when leaving full-screen).
PrintScalingPrintScalingRead/WriteThe /PrintScaling viewer preference.
DuplexPrintDuplexRead/WriteThe /Duplex viewer preference (default Simplex when unset).
DirectionDirectionRead/WriteThe /Direction viewer preference (text-flow direction).
CryptoAlgorithmCryptoAlgorithm?ReadThe encryption algorithm in use, or null when the document is not encrypted.
IdId?ReadThe /ID array from the trailer, or null when no /ID entry is present.
IsPdfUaCompliantboolReadTrue when the document’s XMP metadata carries a pdfuaid:part entry (PDF/UA-1 identifier).
Languagestring?Read/WriteThe natural language of the document (BCP 47).
IsTaggedboolReadWhether the document is tagged PDF.
HasStructTreeboolReadWhether the document has a structure tree.
StructTreeRootAspose.Pdf.Tagged.StructTreeRoot?ReadThe structure-tree root (/StructTreeRoot) for reading a tagged document’s logical structure, or null when the document is not tagged.
LogicalStructureAspose.Pdf.Structure.RootElementReadThe root of the document’s logical-structure tree.
TaggedContentTagged.ITaggedContentReadTagged-content surface for accessibility metadata and the logical-structure tree.
OptimizeSizeboolRead/WriteGets or sets a flag indicating whether the document should be optimized for size on save.
EmbedStandardFontsboolRead/WriteWhen 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.
IgnoreCorruptedObjectsboolRead/WriteWhen true, the parser tolerates corrupted indirect-object declarations (extra/garbled bytes between objects) instead of throwing.
BackgroundColor?Read/WriteDocument-wide background colour painted on every page before content during Save.
ActionsAnnotations.DocumentActionCollectionReadCatalog /AA additional-action dictionary.
CustomSecurityHandlerSecurity.ICustomSecurityHandler?ReadStored custom security handler when set via the ICustomSecurityHandler Encrypt overloads.
AllowReusePageContentboolRead/WriteWhether the saver may reuse identical page-content streams.
EnableNotificationLoggingboolRead/WriteWhether the document emits notification log entries.
HandleSignatureChangeboolRead/WriteWhether signature fields fire change-handlers when their dict mutates.
HideMenubarboolRead/WriteViewer preference: hide the menu bar (/ViewerPreferences /HideMenubar).
HideToolBarboolRead/WriteViewer preference: hide the toolbar (/ViewerPreferences /HideToolbar).
HideWindowUIboolRead/WriteViewer preference: hide window UI chrome (/ViewerPreferences /HideWindowUI).
IsXrefGapsAllowedboolRead/WriteAllow gaps in the xref table during parse.
PickTrayByPdfSizeboolRead/WriteViewer preference: pick the paper tray by PDF page size (/ViewerPreferences /PickTrayByPDFSize).
FileSizeLimitToMemoryLoadingintRead/WriteMaximum file size (bytes) loaded entirely into memory.
DefaultNodesNumInSubtreesbyteReadDefault page-tree branching factor (PDF table 30 /Count vs /Kids ratio).

Methods

SignatureDescription
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.

See Also