Document
Overview
Document is a class in Aspose.Pdf FOSS for Java.
Inherits from: Closeable.
The central class for working with PDF documents (ISO 32000-1:2008).
Properties
| Name | Type | Access | Description |
|---|---|---|---|
background | Color | Read | Returns the document-level background colour set via |
| {@link #setBackground(Color)}, or {@code null} for none. | |||
pages | PageCollection | Read | |
info | DocumentInfo | Read | Returns the document information dictionary, or {@code null} if the |
| trailer has no {@code /Info} entry. | |||
orCreateInfo | DocumentInfo | Read | Returns the document information dictionary, creating and attaching an |
| empty {@code /Info} dictionary to the trailer if none exists. | |||
metadata | XmpMetadata | Read | Returns the XMP metadata of this document. |
version | String | Read | Returns the PDF version string (e.g. |
catalog | COSDictionary | Read | Returns the root catalog dictionary. |
trailer | COSDictionary | Read | Returns the trailer dictionary. |
parser | PDFParser | Read | Returns the underlying PDF parser (for internal use by engine components). |
outlines | OutlineCollection | Read | Returns the document outline (bookmarks) collection. |
form | Form | Read | Returns the interactive form (AcroForm) of this document. |
embeddedFiles | EmbeddedFileCollection | Read | Returns the collection of embedded files (attachments). |
collection | Collection | Read | Returns the document’s portfolio {@link Collection}, instantiating an |
| empty one on first access. | |||
fontUtilities | FontUtilities | Read | Returns the font utilities for this document. |
embedStandardFonts | boolean | Read | Returns whether the standard 14 PDF fonts should be embedded when saving. |
layers | java.util.List<Layer> | Read | Returns the list of Optional Content Groups (layers). |
viewerPreferences | ViewerPreferences | Read | Returns the viewer preferences. |
hideToolbar | boolean | Read | Hide toolbar preference. |
hideMenubar | boolean | Read | Hide menubar preference. |
hideWindowUI | boolean | Read | Hide window UI preference. |
fitWindow | boolean | Read | Fit window preference. |
centerWindow | boolean | Read | Center window preference. |
displayDocTitle | boolean | Read | Display document title preference. |
pageLayout | String | Read | Page layout (SinglePage, OneColumn, TwoColumnLeft, etc.). |
pageMode | PageMode | Read | |
pageInfo | PageInfo | Read | Saves the document to a file. |
linearized | boolean | Read | Returns whether the current document is linearized for fast web view. |
sourcePath | String | Read | Returns the file path this document was loaded from, or {@code null} for new documents |
| or documents loaded from streams. | |||
fileName | String | Read | Returns the file name (path) this document was opened from. |
namedDestinations | NamedDestinations | Read | Returns the document’s named destinations collection. |
pageLabels | PageLabels | Read | Returns the page labels, or {@code null} if {@code /PageLabels} is not present. |
taggedContent | TaggedContent | Read | Returns the document’s tagged content, providing access to the logical structure tree. |
logicalStructure | StructTreeRoot | Read | Returns the logical structure tree for reading. |
encrypted | boolean | Read | Returns true if this document is encrypted. |
javaScript | JavaScriptCollection | Read | Returns the JavaScript collection from the document’s name tree. |
pdfaCompliant | boolean | Read | Returns true if this document is PDF/A compliant. |
pdfFormat | PdfFormat | Read | Returns the PDF format of this document after conversion. |
Methods
| Signature | Description |
|---|---|
Document(filePath: String) | Creates a Document from the file at the given path. |
Document(filePath: String, password: String) | Creates a Document from the file at the given path using the specified password. |
Document(filePath: String, password: String, customHandler: ICustomSecurityHandler) | Creates a Document from the file at the given path using a custom security handler. |
Document(stream: InputStream) | Creates a Document from the given input stream. |
Document(stream: InputStream, password: String) | Creates a Document from the given input stream using the specified password. |
Document(stream: InputStream, password: String, customHandler: ICustomSecurityHandler) | Creates a Document from the given input stream using a custom security handler. |
Document() | Creates a new empty PDF document. |
Document(filePath: String, options: HtmlLoadOptions) | Creates a PDF document from an HTML file. |
Document(stream: InputStream, options: HtmlLoadOptions) | Creates a PDF document from an HTML input stream. |
getBackground() → Color | Returns the document-level background colour set via |
| {@link #setBackground(Color)}, or {@code null} for none. | |
setBackground(color: Color) | Applies a solid background colour to every page in the document |
| (via {@link Page#setBackground(Color)}). | |
getPages() → PageCollection | |
getInfo() → DocumentInfo | Returns the document information dictionary, or {@code null} if the |
| trailer has no {@code /Info} entry. | |
getOrCreateInfo() → DocumentInfo | Returns the document information dictionary, creating and attaching an |
| empty {@code /Info} dictionary to the trailer if none exists. | |
getMetadata() → XmpMetadata | Returns the XMP metadata of this document. |
setXmpMetadata(stream: InputStream) | Sets the XMP metadata from raw XML bytes read from a stream. |
getXmpMetadata(stream: OutputStream) | Writes the XMP metadata XML bytes to the given output stream. |
getVersion() → String | Returns the PDF version string (e.g. |
getCatalog() → COSDictionary | Returns the root catalog dictionary. |
getTrailer() → COSDictionary | Returns the trailer dictionary. |
getParser() → PDFParser | Returns the underlying PDF parser (for internal use by engine components). |
getOutlines() → OutlineCollection | Returns the document outline (bookmarks) collection. |
getForm() → Form | Returns the interactive form (AcroForm) of this document. |
getEmbeddedFiles() → EmbeddedFileCollection | Returns the collection of embedded files (attachments). |
getCollection() → Collection | Returns the document’s portfolio {@link Collection}, instantiating an |
| empty one on first access. | |
setCollection(value: Collection) | Replaces (or removes, when {@code value == null}) the document |
| portfolio. | |
getFontUtilities() → FontUtilities | Returns the font utilities for this document. |
isEmbedStandardFonts() → boolean | Returns whether the standard 14 PDF fonts should be embedded when saving. |
setEmbedStandardFonts(embed: boolean) | Sets whether the standard 14 PDF fonts should be embedded when saving. |
getLayers() → java.util.List<Layer> | Returns the list of Optional Content Groups (layers). |
getViewerPreferences() → ViewerPreferences | Returns the viewer preferences. |
getHideToolbar() → boolean | Hide toolbar preference. |
setHideToolbar(v: boolean) | Sets hide toolbar preference. |
getHideMenubar() → boolean | Hide menubar preference. |
setHideMenubar(v: boolean) | Sets hide menubar preference. |
getHideWindowUI() → boolean | Hide window UI preference. |
setHideWindowUI(v: boolean) | Sets hide window UI preference. |
getFitWindow() → boolean | Fit window preference. |
setFitWindow(v: boolean) | Sets fit window preference. |
getCenterWindow() → boolean | Center window preference. |
setCenterWindow(v: boolean) | Sets center window preference. |
getDisplayDocTitle() → boolean | Display document title preference. |
setDisplayDocTitle(v: boolean) | Sets display document title preference. |
getPageLayout() → String | Page layout (SinglePage, OneColumn, TwoColumnLeft, etc.). |
setPageLayout(layout: String) | Sets page layout. |
getPageMode() → PageMode | |
setPageMode(mode: PageMode) | Sets the page mode. |
getPageInfo() → PageInfo | Saves the document to a file. |
processParagraphs() | Processes paragraphs for all pages (layout pass). |
save(filePath: String) | @param filePath the output file path |
| @throws IOException if writing fails | |
| @throws IllegalArgumentException if filePath is null | |
| / | |
save() | Saves the document back to its associated target path. |
save(outputStream: OutputStream) | Saves the document to an output stream. |
hasIncrementalUpdate() → boolean | Returns whether the current document contains incremental updates. |
optimize() | Requests a full rewrite on the next save instead of an incremental append. |
requestFullRewrite() | Requests that the next save operation performs a full rewrite even if |
| incremental save would otherwise be possible. | |
isLinearized() → boolean | Returns whether the current document is linearized for fast web view. |
optimizeResources() | Removes unused page-level resources before the next save. |
save(filePath: String, format: SaveFormat) | Saves the document in the specified format. |
save(filePath: String, options: PdfSaveOptions) | Saves the document with the specified PDF save options. |
save(filePath: String, options: HtmlSaveOptions) | Saves the document as HTML with the specified options. |
getSourcePath() → String | Returns the file path this document was loaded from, or {@code null} for new documents |
| or documents loaded from streams. | |
getFileName() → String | Returns the file name (path) this document was opened from. |
setFileName(fileName: String) | Sets the file name associated with this document. |
exportAnnotationsToXfdf(filePath: String) | Exports all annotations from this document to an XFDF file. |
exportAnnotationsToXfdf(stream: OutputStream) | Exports all annotations from this document to an XFDF output stream. |
importAnnotationsFromXfdf(filePath: String) | Imports annotations from an XFDF file into this document. |
importAnnotationsFromXfdf(stream: InputStream) | Imports annotations from an XFDF input stream into this document. |
flatten() | Flattens the entire document: bakes all annotation and form field appearances |
| into page content streams, then removes annotations and form fields. | |
flatten(settings: Form.FlattenSettings) | Flattens the document using the specified form flatten settings. |
getNamedDestinations() → NamedDestinations | Returns the document’s named destinations collection. |
getPageLabels() → PageLabels | Returns the page labels, or {@code null} if {@code /PageLabels} is not present. |
getTaggedContent() → TaggedContent | Returns the document’s tagged content, providing access to the logical structure tree. |
getLogicalStructure() → StructTreeRoot | Returns the logical structure tree for reading. |
allocateObjectNumber() → int | Allocates a new object number for a new indirect object. |
registerImportedObject(body: COSBase) → COSObjectReference | Registers an object imported from another document under a freshly allocated |
| key. | |
isEncrypted() → boolean | Returns true if this document is encrypted. |
encrypt(userPassword: String, ownerPassword: String, permissions: int, cryptoAlgorithm: CryptoAlgorithm) | Encrypts the document with user and owner passwords using the specified algorithm. |
encrypt(userPassword: String, ownerPassword: String, privilege: org.aspose.pdf.facades.DocumentPrivilege, customHandler: ICustomSecurityHandler) | Encrypts the document with a custom security handler. |
encrypt(userPassword: String, ownerPassword: String, privilege: org.aspose.pdf.facades.DocumentPrivilege, cryptoAlgorithm: CryptoAlgorithm, usePdf20: boolean) | Encrypts the document with user and owner passwords using the specified algorithm |
| and privilege set. | |
decrypt() | Decrypts the document, removing encryption. |
getJavaScript() → JavaScriptCollection | Returns the JavaScript collection from the document’s name tree. |
validate(outputLogPath: String, format: PdfFormat) → boolean | Validates the document against the specified PDF format profile. |
validate(logStream: OutputStream, format: PdfFormat) → boolean | Validates the document against the specified PDF format profile. |
validate(options: PdfFormatConversionOptions) → boolean | Validates the document using a PDF/A validation option object. |
convert(outputLogPath: String, format: PdfFormat, action: ConvertErrorAction) → boolean | Converts the document to the specified PDF format. |
convert(logStream: OutputStream, format: PdfFormat, action: ConvertErrorAction) → boolean | Converts the document to the specified PDF format. |
convert(logStream: OutputStream, format: PdfFormat, action: ConvertErrorAction, transparencyAction: ConvertTransparencyAction) → boolean | Converts with explicit transparency handling. |
convert(options: PdfFormatConversionOptions) → boolean | Converts using detailed conversion options. |
convertToPdfA2B(outputLogPath: String) → boolean | Converts this PDF to PDF/A-2B format. |
convertToPdfA2B(logStream: OutputStream) → boolean | Converts this PDF to PDF/A-2B format. |
repair() | Attempts to repair minor structural issues before save, validation or |
| conversion workflows. | |
isPdfaCompliant() → boolean | Returns true if this document is PDF/A compliant. |
getPdfFormat() → PdfFormat | Returns the PDF format of this document after conversion. |
close() | Closes the document and releases underlying resources. |