Class Document
- java.lang.Object
-
- com.pdftools.toolbox.internal.NativeBase
-
- com.pdftools.toolbox.internal.NativeObject
-
- com.pdftools.toolbox.pdf.Document
-
- All Implemented Interfaces:
java.lang.AutoCloseable
public class Document extends NativeObject implements java.lang.AutoCloseable
A class representing a PDF document.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Close the objectstatic Documentcreate(Stream stream, Conformance conformance, Encryption encryption)Create a new PDF document.static DocumentcreateWithFdf(Stream pdfStream, Stream fdfStream, Conformance conformance, Encryption encryption)Create a new PDF document and an associated FDF.FileReferenceListgetAllEmbeddedFiles()plain embedded, associated, and attached files (Getter)FileReferenceListgetAssociatedFiles()document-associated files (Getter)ConformancegetConformance()the claimed conformance of the document.FieldNodeMapgetFormFields()The form fields of the document (Getter)booleangetIsLinearized()Whether the document is linearized.booleangetIsPdfUaConformant()Whether the document is declared as PDF/UA conformantjava.lang.StringgetLanguage()the default language for the document.MetadatagetMetadata()the metadata of the document.DestinationgetOpenDestination()The destination that is displayed when the document is opened.OptionalContentGroupListgetOptionalContentGroups()The optional content groups (layers) of the document.OutlineItemListgetOutline()The document outline, also known as "Bookmarks".IccBasedColorSpacegetOutputIntent()the output intent of the document.PageListgetPages()the pages of the document.java.util.EnumSet<Permission>getPermissions()The permissions in force for this document.FileReferenceListgetPlainEmbeddedFiles()plain embedded files (Getter)SignatureFieldListgetSignatureFields()The signature fields of the document (Getter)ViewerSettingsgetViewerSettings()The settings to use when opening the document in a viewer.static Documentopen(Stream stream, java.lang.String password)Open a PDF document.static DocumentopenWithFdf(Stream pdfStream, Stream fdfStream, java.lang.String password)Open a PDF document together with an FDF file.voidsetLanguage(java.lang.String value)the default language for the document.voidsetMetadata(Metadata value)the metadata of the document.voidsetOpenDestination(Destination value)The destination that is displayed when the document is opened.voidsetOutputIntent(IccBasedColorSpace value)the output intent of the document.booleansetPdfUaConformant()Declare the document as PDF/UA conformantvoidsetViewerSettings(ViewerSettings value)The settings to use when opening the document in a viewer.-
Methods inherited from class com.pdftools.toolbox.internal.NativeObject
equals, hashCode
-
-
-
-
Method Detail
-
open
public static Document open(Stream stream, java.lang.String password) throws java.io.IOException, CorruptException, PasswordException, ConformanceException, UnsupportedFeatureException
Open a PDF document.
Documents opened with this method are read-only and cannot be modified.- Parameters:
stream-The stream where the PDF document is stored.
Read access is required.
password- the password to open the PDF document- Returns:
- the newly created document instance
- Throws:
PasswordException- if the file is encrypted and the password is not valid.java.io.IOException- Error reading from the stream.CorruptException- if the file is corrupt or not a PDF.UnsupportedFeatureException- if the file is a PDF collection.UnsupportedFeatureException- if the PDF contains unrendered XFA fields.ConformanceException- if the document's conformance level is not supportedjava.lang.IllegalArgumentException- ifstreamisnull
-
openWithFdf
public static Document openWithFdf(Stream pdfStream, Stream fdfStream, java.lang.String password) throws java.io.IOException, CorruptException, PasswordException, ConformanceException, UnsupportedFeatureException
Open a PDF document together with an FDF file.
Documents opened with this method are read-only and cannot be modified.- Parameters:
pdfStream-The stream where the PDF document is stored.
Read access is required.
fdfStream-The stream where the FDF file is stored.
Read access is required.
password- the password to open the PDF document- Returns:
- the newly created document instance
- Throws:
PasswordException- if the file is encrypted and thepasswordis not valid.java.io.IOException- Error reading from the stream.CorruptException- if the file is corrupt or not a PDF.UnsupportedFeatureException- if the file is a PDF collection.UnsupportedFeatureException- if the PDF contains unrendered XFA fields.ConformanceException- if the document's conformance level is not supportedjava.lang.IllegalArgumentException- ifpdfStreamisnulljava.lang.IllegalArgumentException- iffdfStreamisnull
-
create
public static Document create(Stream stream, Conformance conformance, Encryption encryption) throws java.io.IOException, ConformanceException
Create a new PDF document.
Documents with created with this method are writable and can be modified.- Parameters:
stream-The stream where the PDF document is stored.
Both, read and write access is required.
conformance-The required conformance level of the PDF document. Adding pages or content from incompatible documents or using incompatible features will lead to a conformance error.
When using
null, the conformance is determined automatically, based on the conformance of the input documents and the requirements of the used features.Note that for PDF/A document it is highly recommended to set an output intent using
setOutputIntent(com.pdftools.toolbox.pdf.content.IccBasedColorSpace).encryption- the optional encryption parameters- Returns:
- the newly created document instance
- Throws:
java.io.IOException- Error writing to the stream.ConformanceException- If the conformance level is lower than 1.7 and Unicode passwords are specified. In this context "a Unicode password" is essentially one containing characters that are not in the Windows ANSI encoding (Windows Code Page 1252).java.lang.IllegalArgumentException- ifstreamisnull
-
createWithFdf
public static Document createWithFdf(Stream pdfStream, Stream fdfStream, Conformance conformance, Encryption encryption) throws java.io.IOException, ConformanceException
Create a new PDF document and an associated FDF.
Documents with created with this method are writable and can be modified. When creating a document with this method, allannotations.MarkupAnnotations - created or copied - are stored as an FDF file to thefdfStream. In the output PDF (pdfStream), only annotations that are notannotations.MarkupAnnotations are stored.- Parameters:
pdfStream-The stream where the PDF document is stored.
Both, read and write access is required. The resulting PDF document contains no
annotations.MarkupAnnotations.fdfStream-The stream where the document's
annotations.MarkupAnnotations are stored in the FDF format.Both, read and write access is required.
conformance-The required conformance level of the PDF document. Adding pages or content from incompatible documents or using incompatible features will lead to a conformance error.
When using
null, the conformance is determined automatically, based on the conformance of the input documents and the requirements of the used features.Note that for PDF/A document it is highly recommended to set an output intent using
setOutputIntent(com.pdftools.toolbox.pdf.content.IccBasedColorSpace).encryption- the optional encryption parameters- Returns:
- the newly created document instance
- Throws:
java.io.IOException- Error writing to thepdfStreamConformanceException- If the conformance level is lower than 1.7 and Unicode passwords are specified. In this context "a Unicode password" is essentially one containing characters that are not in the Windows ANSI encoding (Windows Code Page 1252).java.lang.IllegalArgumentException- ifpdfStreamisnulljava.lang.IllegalArgumentException- iffdfStreamisnull
-
setPdfUaConformant
public boolean setPdfUaConformant() throws java.io.IOExceptionDeclare the document as PDF/UA conformant- Returns:
- Throws:
java.io.IOException- Error writing to the stream.
-
getIsPdfUaConformant
public boolean getIsPdfUaConformant() throws java.io.IOExceptionWhether the document is declared as PDF/UA conformant- Throws:
java.io.IOException- Error reading from the stream.
-
getLanguage
public java.lang.String getLanguage()
the default language for the document. (Getter)
A language identifier specifying the natural language for all text in the document except where overridden by language specifications for structure elements or marked content. If this entry is absent, the language is considered unknown.- Throws:
java.lang.IllegalStateException- if the document has already been closed
-
setLanguage
public void setLanguage(java.lang.String value)
the default language for the document. (Setter)
A language identifier specifying the natural language for all text in the document except where overridden by language specifications for structure elements or marked content. If this entry is absent, the language is considered unknown.- Throws:
java.lang.IllegalStateException- if the document has already been closed
-
getOptionalContentGroups
public OptionalContentGroupList getOptionalContentGroups()
The optional content groups (layers) of the document. (Getter)
- Throws:
java.lang.IllegalStateException- if the document has already been closed
-
getConformance
public Conformance getConformance()
the claimed conformance of the document. (Getter)
This method only returns the claimed conformance level, the document is not validated.- Throws:
java.lang.IllegalStateException- if the document has already been closed
-
getMetadata
public Metadata getMetadata()
the metadata of the document. (Getter)
If the document is writable, the metadata object will be writable too and all changes to the metadata object are reflected in the document.- Throws:
java.lang.IllegalStateException- if the document has already been closed
-
setMetadata
public void setMetadata(Metadata value)
the metadata of the document. (Setter)
If the document is writable, the metadata object will be writable too and all changes to the metadata object are reflected in the document.- Throws:
java.lang.IllegalStateException- if the document has already been closedjava.lang.UnsupportedOperationException- if the document is read-onlyjava.lang.IllegalArgumentException- if the givenMetadataobject isnulljava.lang.IllegalArgumentException- if the givenMetadataobject belongs to a different documentjava.lang.IllegalArgumentException- if the givenMetadataobject has already been closedjava.lang.IllegalArgumentException- ifvalueisnull
-
getPages
public PageList getPages()
the pages of the document. (Getter)
If the document is writable, it is possible to append new pages to the end of the list.- Throws:
java.lang.IllegalStateException- if the document has already been closed
-
getOutputIntent
public IccBasedColorSpace getOutputIntent()
the output intent of the document. (Getter)
The output intent specifies a color profile that characterizes the intended output device. It is used to render device colors on devices other than the intended output device.- Throws:
java.lang.IllegalStateException- if the document has already been closed
-
setOutputIntent
public void setOutputIntent(IccBasedColorSpace value)
the output intent of the document. (Setter)
The output intent specifies a color profile that characterizes the intended output device. It is used to render device colors on devices other than the intended output device.- Throws:
java.lang.IllegalStateException- if the document has already been closedjava.lang.UnsupportedOperationException- if the document is read-onlyjava.lang.UnsupportedOperationException- if an output intent has been set alreadyjava.lang.IllegalArgumentException- if the givencontent.IccBasedColorSpaceobject isnulljava.lang.IllegalArgumentException- if the givencontent.IccBasedColorSpaceobject has already been closedjava.lang.IllegalArgumentException- if the givencontent.IccBasedColorSpaceobject> is associated with a different document
-
getFormFields
public FieldNodeMap getFormFields() throws CorruptException
The form fields of the document (Getter)
This list contains all AcroForm form fields that belong to this document. Adding to this list results in an error:- IllegalState if the list has already been closed
- UnsupportedOperation if the document is read-only
-
IllegalArgument
-
if the given form field node is
null - if the given form field node has already been closed
- if the given form field node does not belong to the same document as the list
- if the given form field node has already been added to a form field node list
- if the given form field node's identifier equals an identifier of one of the form field nodes in this list
-
if the given form field node is
- Throws:
java.lang.IllegalStateException- if the document has already been closedCorruptException- if the document contains corrupt form fields
-
getSignatureFields
public SignatureFieldList getSignatureFields()
The signature fields of the document (Getter)
Signature fields are a special kind of form fields, that can contain digital signatures.- Throws:
java.lang.IllegalStateException- if the document has already been closed
-
getPlainEmbeddedFiles
public FileReferenceList getPlainEmbeddedFiles()
plain embedded files (Getter)
This list contains plain embedded files, i.e., files that are embedded in this document without having a specific association (
getAssociatedFiles()), and without being contained in anyannotations.FileAttachment.If the document is writable, then it is possible to append new file references to the list. Every file reference object can occur at most once in this list.
For PDF/A-3 documents, appending to this list results in a Conformance error.
- Throws:
java.lang.IllegalStateException- if the document has already been closed
-
getAssociatedFiles
public FileReferenceList getAssociatedFiles()
document-associated files (Getter)
This list contains associated files, whose associated object is the document.
If the document is writable, then it is possible to append new file references to the list. Every file reference object can occur at most once in this list.
Appending to this list results in a Conformance error if the document's conformance is neither PDF/A-3 nor can be upgraded to PDF 2.0.
- Throws:
java.lang.IllegalStateException- if the document has already been closed
-
getAllEmbeddedFiles
public FileReferenceList getAllEmbeddedFiles()
plain embedded, associated, and attached files (Getter)
This read-only list contains the union of all plain embedded files, associated files, and files contained in file attachment annotations. This is the list of files contained in a PDF as presented in a PDF viewer.
This list does not support appending.
- Throws:
java.lang.IllegalStateException- if the document has already been closed
-
getOutline
public OutlineItemList getOutline()
The document outline, also known as "Bookmarks".- Throws:
java.lang.IllegalStateException- if the document has already been closed
-
getOpenDestination
public Destination getOpenDestination()
The destination that is displayed when the document is opened.- Throws:
java.lang.IllegalStateException- if the document has already been closed
-
setOpenDestination
public void setOpenDestination(Destination value)
The destination that is displayed when the document is opened.- Throws:
java.lang.IllegalStateException- if the document has already been closedjava.lang.UnsupportedOperationException- if the document is read-onlyjava.lang.IllegalArgumentException- if the destination is associated with a different documentjava.lang.IllegalArgumentException- if the destination has already been closed
-
getPermissions
public java.util.EnumSet<Permission> getPermissions()
The permissions in force for this document. This property isnullif the document is not encrypted.- Throws:
java.lang.IllegalStateException- if the document has already been closed
-
getViewerSettings
public ViewerSettings getViewerSettings()
The settings to use when opening the document in a viewer.- Throws:
java.lang.IllegalStateException- if the document has already been closed
-
setViewerSettings
public void setViewerSettings(ViewerSettings value)
The settings to use when opening the document in a viewer.- Throws:
java.lang.IllegalStateException- if the document has already been closedjava.lang.UnsupportedOperationException- if the document is read-onlyjava.lang.IllegalArgumentException- if viewer settings are associated with a different documentjava.lang.IllegalArgumentException- ifvalueisnull
-
getIsLinearized
public boolean getIsLinearized()
Whether the document is linearized.
Linearization is also known as "Fast Web View" and is a way of optimizing PDFs so they can be streamed into a client application. This helps online documents open almost instantly, without having to wait for a large document to completely download.
- Throws:
java.lang.IllegalStateException- if the document has already been closed
-
close
public void close() throws ToolboxException, java.io.IOExceptionClose the object
Release all native resources associated with the object.- Specified by:
closein interfacejava.lang.AutoCloseable- Throws:
ToolboxException- only explicitly stated in a superclassjava.io.IOException
-
-