public class PDDocument extends Object implements Closeable
Constructor and Description |
---|
PDDocument()
Creates an empty PDF document.
|
PDDocument(COSDocument doc)
Constructor that uses an existing document.
|
PDDocument(COSDocument doc,
RandomAccessRead source)
Constructor that uses an existing document.
|
PDDocument(COSDocument doc,
RandomAccessRead source,
AccessPermission permission)
Constructor that uses an existing document.
|
PDDocument(MemoryUsageSetting memUsageSetting)
Creates an empty PDF document.
|
Modifier and Type | Method and Description |
---|---|
void |
addPage(PDPage page)
This will add a page to the document.
|
void |
addSignature(PDSignature sigObject,
SignatureInterface signatureInterface)
Add a signature.
|
void |
addSignature(PDSignature sigObject,
SignatureInterface signatureInterface,
SignatureOptions options)
This will add a signature to the document.
|
void |
addSignatureField(List<PDSignatureField> sigFields,
SignatureInterface signatureInterface,
SignatureOptions options)
This will add a signature field to the document.
|
void |
close()
This will close the underlying COSDocument object.
|
AccessPermission |
getCurrentAccessPermission()
Returns the access permissions granted when the document was decrypted.
|
COSDocument |
getDocument()
This will get the low level document.
|
PDDocumentCatalog |
getDocumentCatalog()
This will get the document CATALOG.
|
Long |
getDocumentId()
Provides the document ID.
|
PDDocumentInformation |
getDocumentInformation()
This will get the document info dictionary.
|
PDEncryption |
getEncryption()
This will get the encryption dictionary for this document.
|
PDSignature |
getLastSignatureDictionary()
This will return the last signature.
|
int |
getNumberOfPages()
This will return the total page count of the PDF document.
|
PDPage |
getPage(int pageIndex)
Returns the page at the given index.
|
PDPageTree |
getPages() |
ResourceCache |
getResourceCache()
Returns the resource cache associated with this document, or null if there is none.
|
List<PDSignature> |
getSignatureDictionaries()
Retrieve all signature dictionaries from the document.
|
List<PDSignatureField> |
getSignatureFields()
Retrieve all signature fields from the document.
|
float |
getVersion()
Returns the PDF specification version this document conforms to.
|
PDPage |
importPage(PDPage page)
This will import and copy the contents from another location.
|
boolean |
isAllSecurityToBeRemoved()
Indicates if all security is removed or not when writing the pdf.
|
boolean |
isEncrypted()
This will tell if this document is encrypted or not.
|
static PDDocument |
load(byte[] input)
Parses a PDF.
|
static PDDocument |
load(byte[] input,
String password)
Parses a PDF.
|
static PDDocument |
load(byte[] input,
String password,
InputStream keyStore,
String alias)
Parses a PDF.
|
static PDDocument |
load(byte[] input,
String password,
InputStream keyStore,
String alias,
MemoryUsageSetting memUsageSetting)
Parses a PDF.
|
static PDDocument |
load(File file)
Parses a PDF.
|
static PDDocument |
load(File file,
MemoryUsageSetting memUsageSetting)
Parses a PDF.
|
static PDDocument |
load(File file,
String password)
Parses a PDF.
|
static PDDocument |
load(File file,
String password,
InputStream keyStore,
String alias)
Parses a PDF.
|
static PDDocument |
load(File file,
String password,
InputStream keyStore,
String alias,
MemoryUsageSetting memUsageSetting)
Parses a PDF.
|
static PDDocument |
load(File file,
String password,
MemoryUsageSetting memUsageSetting)
Parses a PDF.
|
static PDDocument |
load(InputStream input)
Parses a PDF.
|
static PDDocument |
load(InputStream input,
MemoryUsageSetting memUsageSetting)
Parses a PDF.
|
static PDDocument |
load(InputStream input,
String password)
Parses a PDF.
|
static PDDocument |
load(InputStream input,
String password,
InputStream keyStore,
String alias)
Parses a PDF.
|
static PDDocument |
load(InputStream input,
String password,
InputStream keyStore,
String alias,
MemoryUsageSetting memUsageSetting)
Parses a PDF.
|
static PDDocument |
load(InputStream input,
String password,
MemoryUsageSetting memUsageSetting)
Parses a PDF.
|
void |
protect(ProtectionPolicy policy)
Protects the document with a protection policy.
|
void |
removePage(int pageNumber)
Remove the page from the document.
|
void |
removePage(PDPage page)
Remove the page from the document.
|
void |
save(File file)
Save the document to a file.
|
void |
save(OutputStream output)
This will save the document to an output stream.
|
void |
save(String fileName)
Save the document to a file.
|
void |
saveIncremental(OutputStream output)
Save the PDF as an incremental update.
|
void |
setAllSecurityToBeRemoved(boolean removeAllSecurity)
Activates/Deactivates the removal of all security when writing the pdf.
|
void |
setDocumentId(Long docId)
Sets the document ID to the given value.
|
void |
setDocumentInformation(PDDocumentInformation info)
This will set the document information for this document.
|
void |
setEncryptionDictionary(PDEncryption encryption)
This will set the encryption dictionary for this document.
|
void |
setResourceCache(ResourceCache resourceCache)
Sets the resource cache associated with this document.
|
void |
setVersion(float newVersion)
Sets the PDF specification version for this document.
|
public PDDocument()
public PDDocument(MemoryUsageSetting memUsageSetting)
memUsageSetting
- defines how memory is used for buffering PDF streamspublic PDDocument(COSDocument doc)
doc
- The COSDocument that this document wraps.public PDDocument(COSDocument doc, RandomAccessRead source)
doc
- The COSDocument that this document wraps.source
- the parser which is used to read the pdfpublic PDDocument(COSDocument doc, RandomAccessRead source, AccessPermission permission)
doc
- The COSDocument that this document wraps.source
- the parser which is used to read the pdfpermission
- he access permissions of the pdfpublic void addPage(PDPage page)
page
- The page to add to the document.public void addSignature(PDSignature sigObject, SignatureInterface signatureInterface) throws IOException
sigObject
- is the PDSignatureField modelsignatureInterface
- is a interface which provides signing capabilitiesIOException
- if there is an error creating required fieldspublic void addSignature(PDSignature sigObject, SignatureInterface signatureInterface, SignatureOptions options) throws IOException
sigObject
- is the PDSignatureField modelsignatureInterface
- is a interface which provides signing capabilitiesoptions
- signature optionsIOException
- if there is an error creating required fieldspublic void addSignatureField(List<PDSignatureField> sigFields, SignatureInterface signatureInterface, SignatureOptions options) throws IOException
sigFields
- are the PDSignatureFields that should be added to the documentsignatureInterface
- is a interface which provides signing capabilitiesoptions
- signature optionsIOException
- if there is an error creating required fieldspublic void removePage(PDPage page)
page
- The page to remove from the document.public void removePage(int pageNumber)
pageNumber
- 0 based index to page number.public PDPage importPage(PDPage page) throws IOException
page
- The page to import.IOException
- If there is an error copying the page.public COSDocument getDocument()
public PDDocumentInformation getDocumentInformation()
public void setDocumentInformation(PDDocumentInformation info)
info
- The updated document information.public PDDocumentCatalog getDocumentCatalog()
public boolean isEncrypted()
public PDEncryption getEncryption()
public void setEncryptionDictionary(PDEncryption encryption) throws IOException
encryption
- The encryption dictionary(most likely a PDStandardEncryption object)IOException
- If there is an error determining which security handler to use.public PDSignature getLastSignatureDictionary() throws IOException
PDSignatureField
.IOException
- if no document catalog can be found.public List<PDSignatureField> getSignatureFields() throws IOException
List
of PDSignatureField
sIOException
- if no document catalog can be found.public List<PDSignature> getSignatureDictionaries() throws IOException
List
of PDSignatureField
sIOException
- if no document catalog can be found.public static PDDocument load(File file) throws IOException
file
- file to be loadedIOException
- in case of a file reading or parsing errorpublic static PDDocument load(File file, MemoryUsageSetting memUsageSetting) throws IOException
file
- file to be loadedmemUsageSetting
- defines how memory is used for buffering PDF streamsIOException
- in case of a file reading or parsing errorpublic static PDDocument load(File file, String password) throws IOException
file
- file to be loadedpassword
- password to be used for decryptionIOException
- in case of a file reading or parsing errorpublic static PDDocument load(File file, String password, MemoryUsageSetting memUsageSetting) throws IOException
file
- file to be loadedpassword
- password to be used for decryptionmemUsageSetting
- defines how memory is used for buffering PDF streamsIOException
- in case of a file reading or parsing errorpublic static PDDocument load(File file, String password, InputStream keyStore, String alias) throws IOException
file
- file to be loadedpassword
- password to be used for decryptionkeyStore
- key store to be used for decryption when using public key securityalias
- alias to be used for decryption when using public key securityIOException
- in case of a file reading or parsing errorpublic static PDDocument load(File file, String password, InputStream keyStore, String alias, MemoryUsageSetting memUsageSetting) throws IOException
file
- file to be loadedpassword
- password to be used for decryptionkeyStore
- key store to be used for decryption when using public key securityalias
- alias to be used for decryption when using public key securitymemUsageSetting
- defines how memory is used for buffering PDF streamsIOException
- in case of a file reading or parsing errorpublic static PDDocument load(InputStream input) throws IOException
input
- stream that contains the document.IOException
- in case of a file reading or parsing errorpublic static PDDocument load(InputStream input, MemoryUsageSetting memUsageSetting) throws IOException
input
- stream that contains the document.memUsageSetting
- defines how memory is used for buffering input stream and PDF streamsIOException
- in case of a file reading or parsing errorpublic static PDDocument load(InputStream input, String password) throws IOException
input
- stream that contains the document.password
- password to be used for decryptionIOException
- in case of a file reading or parsing errorpublic static PDDocument load(InputStream input, String password, InputStream keyStore, String alias) throws IOException
input
- stream that contains the document.password
- password to be used for decryptionkeyStore
- key store to be used for decryption when using public key securityalias
- alias to be used for decryption when using public key securityIOException
- in case of a file reading or parsing errorpublic static PDDocument load(InputStream input, String password, MemoryUsageSetting memUsageSetting) throws IOException
input
- stream that contains the document.password
- password to be used for decryptionmemUsageSetting
- defines how memory is used for buffering input stream and PDF streamsIOException
- in case of a file reading or parsing errorpublic static PDDocument load(InputStream input, String password, InputStream keyStore, String alias, MemoryUsageSetting memUsageSetting) throws IOException
input
- stream that contains the document.password
- password to be used for decryptionkeyStore
- key store to be used for decryption when using public key securityalias
- alias to be used for decryption when using public key securitymemUsageSetting
- defines how memory is used for buffering input stream and PDF streamsIOException
- in case of a file reading or parsing errorpublic static PDDocument load(byte[] input) throws IOException
input
- byte array that contains the document.IOException
- in case of a file reading or parsing errorpublic static PDDocument load(byte[] input, String password) throws IOException
input
- byte array that contains the document.password
- password to be used for decryptionIOException
- in case of a file reading or parsing errorpublic static PDDocument load(byte[] input, String password, InputStream keyStore, String alias) throws IOException
input
- byte array that contains the document.password
- password to be used for decryptionkeyStore
- key store to be used for decryption when using public key securityalias
- alias to be used for decryption when using public key securityIOException
- in case of a file reading or parsing errorpublic static PDDocument load(byte[] input, String password, InputStream keyStore, String alias, MemoryUsageSetting memUsageSetting) throws IOException
input
- byte array that contains the document.password
- password to be used for decryptionkeyStore
- key store to be used for decryption when using public key securityalias
- alias to be used for decryption when using public key securitymemUsageSetting
- defines how memory is used for buffering input stream and PDF streamsIOException
- in case of a file reading or parsing errorpublic void save(String fileName) throws IOException
fileName
- The file to save as.IOException
- if the output could not be writtenpublic void save(File file) throws IOException
file
- The file to save as.IOException
- if the output could not be writtenpublic void save(OutputStream output) throws IOException
output
- The stream to write to.IOException
- if the output could not be writtenpublic void saveIncremental(OutputStream output) throws IOException
output
- stream to writeIOException
- if the output could not be writtenIllegalStateException
- if the document was not loaded from a file.public PDPage getPage(int pageIndex)
pageIndex
- the page indexpublic PDPageTree getPages()
public int getNumberOfPages()
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
- If there is an error releasing resources.public void protect(ProtectionPolicy policy) throws IOException
setAllSecurityToBeRemoved(boolean)
with a false argument if it was set to true
previously and logs a warning.policy
- The protection policy.IOException
- if there isn't any suitable security handler.StandardProtectionPolicy
,
PublicKeyProtectionPolicy
public AccessPermission getCurrentAccessPermission()
public boolean isAllSecurityToBeRemoved()
public void setAllSecurityToBeRemoved(boolean removeAllSecurity)
removeAllSecurity
- remove all security if set to truepublic Long getDocumentId()
public void setDocumentId(Long docId)
docId
- the new document IDpublic float getVersion()
public void setVersion(float newVersion)
newVersion
- the new PDF version (e.g. 1.4f)public ResourceCache getResourceCache()
public void setResourceCache(ResourceCache resourceCache)
resourceCache
- A resource cache, or null.Copyright © 2002–2015 The Apache Software Foundation. All rights reserved.