Package com.pdftools.pdf
Class Document
java.lang.Object
com.pdftools.internal.NativeBase
com.pdftools.internal.NativeObject
com.pdftools.pdf.Document
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
PreparedDocument
The PDF document
PDF documents are either opened usingopen(com.pdftools.sys.Stream) or the result of an operation, e.g. of PDF optimization (see pdftools.optimization.Optimizer.optimizeDocument).-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close the object.The claimed conformance of the document (Getter)booleanWhether the document is linearized (Getter)booleanThe metadata of the document.intThe number of pages in the document (Getter)The access permissions applicable for this document (Getter)getXfa()Whether the document is an XML Forms Architecture (XFA) or a PDF document (Getter)static DocumentOpen a PDF document.static DocumentOpen a PDF document.Methods inherited from class com.pdftools.internal.NativeObject
equals, hashCode
-
Method Details
-
open
public static Document open(Stream stream) throws GenericException, LicenseException, CorruptException, PasswordException, UnsupportedFeatureException Open a PDF document.
Documents opened with this method are read-only and cannot be modified.- Parameters:
stream- The stream from which the PDF is read.- Returns:
- The newly created document instance
- Throws:
LicenseException- The license check has failed.PasswordException- The document is encrypted and thepasswordis invalid.CorruptException- The document is corrupt or not a PDF.UnsupportedFeatureException- The document is an unencrypted wrapper document.GenericException- A generic error occurred.IllegalArgumentException- ifstreamisnull
-
open
public static Document open(Stream stream, String password) throws GenericException, LicenseException, CorruptException, PasswordException, UnsupportedFeatureException Open a PDF document.
Documents opened with this method are read-only and cannot be modified.- Parameters:
stream- The stream from which the PDF is read.password- The password to open the PDF document. Ifnullor empty, no password is used.- Returns:
- The newly created document instance
- Throws:
LicenseException- The license check has failed.PasswordException- The document is encrypted and thepasswordis invalid.CorruptException- The document is corrupt or not a PDF.UnsupportedFeatureException- The document is an unencrypted wrapper document.GenericException- A generic error occurred.IllegalArgumentException- ifstreamisnull
-
getConformance
The claimed conformance of the document (Getter)
This method only returns the claimed conformance level, the document is not validated.
This property can return
nullif the document's conformance is unknown. -
getPageCount
public int getPageCount()The number of pages in the document (Getter)
If the document is a collection (also known as PDF Portfolio), then this property is0. -
getPermissions
The access permissions applicable for this document (Getter)
This property is
null, if the document is not encrypted.Note that these permissions might be different from the "Document Restrictions Summary" displayed in Adobe Acrobat. This is because Acrobat's restrictions are also affected by other factors. For example, "Document Assembly" is generally only allowed in Acrobat Pro and not the Acrobat Reader.
-
getIsLinearized
public boolean getIsLinearized()Whether the document is linearized (Getter)
-
getIsSigned
public boolean getIsSigned() -
getSignatureFields
-
getXfa
Whether the document is an XML Forms Architecture (XFA) or a PDF document (Getter)
While XFA documents may seem like regular PDF documents they are not and cannot be processed by many components (errorUnsupportedFeatureException). An XFA form is included as a resource in a mere shell PDF. The PDF pages' content is generated dynamically from the XFA data, which is a complex, non-standardized process. For this reason, XFA is forbidden by the ISO Standards ISO 19'005-2 (PDF/A-2) and ISO 32'000-2 (PDF 2.0) and newer. It is recommended to convert XFA documents to PDF using an Adobe product, e.g. by using the "Print to PDF" function of Adobe Acrobat Reader. -
getMetadata
The metadata of the document. (Getter)
-
close
Close the object.
Release all resources associated with the object.- Specified by:
closein interfaceAutoCloseable- Throws:
PdfToolsException- only explicitly stated in a superclassIOException
-