public class Document extends NativeObject implements java.lang.AutoCloseable
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the object
|
static Document |
create(Stream stream,
Conformance conformance,
Encryption encryption)
Create a new PDF document.
|
static Document |
createDynamicObject(long handle) |
FileReferenceList |
getAllEmbeddedFiles()
plain embedded, associated, and attached files (Getter)
|
FileReferenceList |
getAssociatedFiles()
document-associated files (Getter)
|
Conformance |
getConformance()
the claimed conformance of the document.
|
FieldNodeMap |
getFormFields()
The form fields of the document (Getter)
|
Metadata |
getMetadata()
the metadata of the document.
|
Destination |
getOpenDestination()
The destination that is displayed when the document is opened.
|
OutlineItemList |
getOutline()
The document outline, also known as "Bookmarks".
|
IccBasedColorSpace |
getOutputIntent()
the output intent of the document.
|
PageList |
getPages()
the pages of the document.
|
java.util.EnumSet<Permission> |
getPermissions()
The permissions in force for this document.
|
FileReferenceList |
getPlainEmbeddedFiles()
plain embedded files (Getter)
|
SignatureFieldList |
getSignatureFields()
The signature fields of the document (Getter)
|
ViewerSettings |
getViewerSettings()
The settings to use when opening the document in a viewer.
|
static Document |
open(Stream stream,
java.lang.String password)
Open a PDF document.
|
static Document |
openWithFdf(Stream pdfStream,
Stream fdfStream,
java.lang.String password)
Open a PDF document together with an FDF file.
|
void |
setMetadata(Metadata value)
the metadata of the document.
|
void |
setOpenDestination(Destination value)
The destination that is displayed when the document is opened.
|
void |
setOutputIntent(IccBasedColorSpace value)
the output intent of the document.
|
void |
setViewerSettings(ViewerSettings value)
The settings to use when opening the document in a viewer.
|
equals, hashCode
public static Document createDynamicObject(long handle)
public static Document open(Stream stream, java.lang.String password) throws java.io.IOException, CorruptException, PasswordException, ConformanceException, UnsupportedFeatureException
stream
- The stream where the PDF document is stored.
Read access is required.
password
- the password to open the PDF documentPasswordException
- 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
- if the stream
argument is null
public static Document openWithFdf(Stream pdfStream, Stream fdfStream, java.lang.String password) throws java.io.IOException, CorruptException, PasswordException, ConformanceException, UnsupportedFeatureException
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 documentPasswordException
- 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
- if the pdfStream
argument is null
java.lang.IllegalArgumentException
- if the fdfStream
argument is null
public static Document create(Stream stream, Conformance conformance, Encryption encryption) throws java.io.IOException
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.pdf_tools.fourheights.pdftoolbox.pdf.content.IccBasedColorSpace)
.
encryption
- the optional encryption parametersjava.io.IOException
- Error writing to the stream.java.lang.IllegalArgumentException
- if the stream
argument is null
public Conformance getConformance()
java.lang.IllegalStateException
- if the document has already been closedpublic Metadata getMetadata()
java.lang.IllegalStateException
- if the document has already been closedpublic void setMetadata(Metadata value)
java.lang.IllegalStateException
- if the document has already been closedjava.lang.UnsupportedOperationException
- if the document is read-onlyjava.lang.IllegalArgumentException
- if the given Metadata
object is null
java.lang.IllegalArgumentException
- if the given Metadata
object belongs to a different documentjava.lang.IllegalArgumentException
- if the given Metadata
object has already been closedpublic PageList getPages()
java.lang.IllegalStateException
- if the document has already been closedpublic IccBasedColorSpace getOutputIntent()
java.lang.IllegalStateException
- if the document has already been closedpublic void setOutputIntent(IccBasedColorSpace value)
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 given content.IccBasedColorSpace
object is null
java.lang.IllegalArgumentException
- if the given content.IccBasedColorSpace
object has already been closedjava.lang.IllegalArgumentException
- if the given content.IccBasedColorSpace
object> is associated with a different documentpublic FieldNodeMap getFormFields() throws CorruptException
null
java.lang.IllegalStateException
- if the document has already been closedCorruptException
- if the document contains corrupt form fieldspublic SignatureFieldList getSignatureFields()
java.lang.IllegalStateException
- if the document has already been closedpublic FileReferenceList getPlainEmbeddedFiles()
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 any annotations.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.
java.lang.IllegalStateException
- if the document has already been closedpublic FileReferenceList getAssociatedFiles()
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.
java.lang.IllegalStateException
- if the document has already been closedpublic FileReferenceList getAllEmbeddedFiles()
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.
java.lang.IllegalStateException
- if the document has already been closedpublic OutlineItemList getOutline()
java.lang.IllegalStateException
- if the document has already been closedpublic Destination getOpenDestination()
java.lang.IllegalStateException
- if the document has already been closedpublic void setOpenDestination(Destination value)
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 closedpublic java.util.EnumSet<Permission> getPermissions()
null
if the document is not encrypted.java.lang.IllegalStateException
- if the document has already been closedpublic ViewerSettings getViewerSettings()
java.lang.IllegalStateException
- if the document has already been closedpublic void setViewerSettings(ViewerSettings value)
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 documentpublic void close() throws PdfToolboxException, java.io.IOException
close
in interface java.lang.AutoCloseable
PdfToolboxException
- only explicitly stated in a superclassjava.io.IOException