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

NameTypeAccessDescription
backgroundColorReadReturns the document-level background colour set via
{@link #setBackground(Color)}, or {@code null} for none.
pagesPageCollectionRead
infoDocumentInfoReadReturns the document information dictionary, or {@code null} if the
trailer has no {@code /Info} entry.
orCreateInfoDocumentInfoReadReturns the document information dictionary, creating and attaching an
empty {@code /Info} dictionary to the trailer if none exists.
metadataXmpMetadataReadReturns the XMP metadata of this document.
versionStringReadReturns the PDF version string (e.g.
catalogCOSDictionaryReadReturns the root catalog dictionary.
trailerCOSDictionaryReadReturns the trailer dictionary.
parserPDFParserReadReturns the underlying PDF parser (for internal use by engine components).
outlinesOutlineCollectionReadReturns the document outline (bookmarks) collection.
formFormReadReturns the interactive form (AcroForm) of this document.
embeddedFilesEmbeddedFileCollectionReadReturns the collection of embedded files (attachments).
collectionCollectionReadReturns the document’s portfolio {@link Collection}, instantiating an
empty one on first access.
fontUtilitiesFontUtilitiesReadReturns the font utilities for this document.
embedStandardFontsbooleanReadReturns whether the standard 14 PDF fonts should be embedded when saving.
layersjava.util.List<Layer>ReadReturns the list of Optional Content Groups (layers).
viewerPreferencesViewerPreferencesReadReturns the viewer preferences.
hideToolbarbooleanReadHide toolbar preference.
hideMenubarbooleanReadHide menubar preference.
hideWindowUIbooleanReadHide window UI preference.
fitWindowbooleanReadFit window preference.
centerWindowbooleanReadCenter window preference.
displayDocTitlebooleanReadDisplay document title preference.
pageLayoutStringReadPage layout (SinglePage, OneColumn, TwoColumnLeft, etc.).
pageModePageModeRead
pageInfoPageInfoReadSaves the document to a file.
linearizedbooleanReadReturns whether the current document is linearized for fast web view.
sourcePathStringReadReturns the file path this document was loaded from, or {@code null} for new documents
or documents loaded from streams.
fileNameStringReadReturns the file name (path) this document was opened from.
namedDestinationsNamedDestinationsReadReturns the document’s named destinations collection.
pageLabelsPageLabelsReadReturns the page labels, or {@code null} if {@code /PageLabels} is not present.
taggedContentTaggedContentReadReturns the document’s tagged content, providing access to the logical structure tree.
logicalStructureStructTreeRootReadReturns the logical structure tree for reading.
encryptedbooleanReadReturns true if this document is encrypted.
javaScriptJavaScriptCollectionReadReturns the JavaScript collection from the document’s name tree.
pdfaCompliantbooleanReadReturns true if this document is PDF/A compliant.
pdfFormatPdfFormatReadReturns the PDF format of this document after conversion.

Methods

SignatureDescription
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()ColorReturns 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()DocumentInfoReturns the document information dictionary, or {@code null} if the
trailer has no {@code /Info} entry.
getOrCreateInfo()DocumentInfoReturns the document information dictionary, creating and attaching an
empty {@code /Info} dictionary to the trailer if none exists.
getMetadata()XmpMetadataReturns 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()StringReturns the PDF version string (e.g.
getCatalog()COSDictionaryReturns the root catalog dictionary.
getTrailer()COSDictionaryReturns the trailer dictionary.
getParser()PDFParserReturns the underlying PDF parser (for internal use by engine components).
getOutlines()OutlineCollectionReturns the document outline (bookmarks) collection.
getForm()FormReturns the interactive form (AcroForm) of this document.
getEmbeddedFiles()EmbeddedFileCollectionReturns the collection of embedded files (attachments).
getCollection()CollectionReturns 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()FontUtilitiesReturns the font utilities for this document.
isEmbedStandardFonts()booleanReturns 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()ViewerPreferencesReturns the viewer preferences.
getHideToolbar()booleanHide toolbar preference.
setHideToolbar(v: boolean)Sets hide toolbar preference.
getHideMenubar()booleanHide menubar preference.
setHideMenubar(v: boolean)Sets hide menubar preference.
getHideWindowUI()booleanHide window UI preference.
setHideWindowUI(v: boolean)Sets hide window UI preference.
getFitWindow()booleanFit window preference.
setFitWindow(v: boolean)Sets fit window preference.
getCenterWindow()booleanCenter window preference.
setCenterWindow(v: boolean)Sets center window preference.
getDisplayDocTitle()booleanDisplay document title preference.
setDisplayDocTitle(v: boolean)Sets display document title preference.
getPageLayout()StringPage layout (SinglePage, OneColumn, TwoColumnLeft, etc.).
setPageLayout(layout: String)Sets page layout.
getPageMode()PageMode
setPageMode(mode: PageMode)Sets the page mode.
getPageInfo()PageInfoSaves 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()booleanReturns 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()booleanReturns 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()StringReturns the file path this document was loaded from, or {@code null} for new documents
or documents loaded from streams.
getFileName()StringReturns 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()NamedDestinationsReturns the document’s named destinations collection.
getPageLabels()PageLabelsReturns the page labels, or {@code null} if {@code /PageLabels} is not present.
getTaggedContent()TaggedContentReturns the document’s tagged content, providing access to the logical structure tree.
getLogicalStructure()StructTreeRootReturns the logical structure tree for reading.
allocateObjectNumber()intAllocates a new object number for a new indirect object.
registerImportedObject(body: COSBase)COSObjectReferenceRegisters an object imported from another document under a freshly allocated
key.
isEncrypted()booleanReturns 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()JavaScriptCollectionReturns the JavaScript collection from the document’s name tree.
validate(outputLogPath: String, format: PdfFormat)booleanValidates the document against the specified PDF format profile.
validate(logStream: OutputStream, format: PdfFormat)booleanValidates the document against the specified PDF format profile.
validate(options: PdfFormatConversionOptions)booleanValidates the document using a PDF/A validation option object.
convert(outputLogPath: String, format: PdfFormat, action: ConvertErrorAction)booleanConverts the document to the specified PDF format.
convert(logStream: OutputStream, format: PdfFormat, action: ConvertErrorAction)booleanConverts the document to the specified PDF format.
convert(logStream: OutputStream, format: PdfFormat, action: ConvertErrorAction, transparencyAction: ConvertTransparencyAction)booleanConverts with explicit transparency handling.
convert(options: PdfFormatConversionOptions)booleanConverts using detailed conversion options.
convertToPdfA2B(outputLogPath: String)booleanConverts this PDF to PDF/A-2B format.
convertToPdfA2B(logStream: OutputStream)booleanConverts this PDF to PDF/A-2B format.
repair()Attempts to repair minor structural issues before save, validation or
conversion workflows.
isPdfaCompliant()booleanReturns true if this document is PDF/A compliant.
getPdfFormat()PdfFormatReturns the PDF format of this document after conversion.
close()Closes the document and releases underlying resources.

See Also