|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.pdfbox.pdmodel.PDDocument
public class PDDocument
This is the in-memory representation of the PDF document. You need to call close() on this object when you are done using it!!
This class implements the Pageable
interface, but since PDFBox
version 1.3.0 you should be using the PDPageable
adapter instead
(see PDFBOX-788).
Field Summary |
---|
Fields inherited from interface java.awt.print.Pageable |
---|
UNKNOWN_NUMBER_OF_PAGES |
Constructor Summary | |
---|---|
PDDocument()
Constructor, creates a new PDF Document with no pages. |
|
PDDocument(COSDocument doc)
Constructor that uses an existing document. |
Method Summary | |
---|---|
void |
addPage(PDPage page)
This will add a page to the document. |
void |
addSignature(PDSignature sigObject,
SignatureInterface signatureInterface)
|
void |
addSignature(PDSignature sigObject,
SignatureInterface signatureInterface,
SignatureOptions options)
This will add a signature to the document. |
void |
clearWillEncryptWhenSaving()
Deprecated. Do not rely on this method anymore. It is the responsability of COSWriter to hold this state. |
void |
close()
This will close the underlying COSDocument object. |
void |
decrypt(String password)
This will decrypt a document. |
void |
encrypt(String ownerPassword,
String userPassword)
This will mark a document to be encrypted. |
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. |
PDDocumentInformation |
getDocumentInformation()
This will get the document info dictionary. |
PDEncryptionDictionary |
getEncryptionDictionary()
This will get the encryption dictionary for this document. |
int |
getNumberOfPages()
|
String |
getOwnerPasswordForEncryption()
Deprecated. Do not rely on this method anymore. |
int |
getPageCount()
Deprecated. Use the getNumberOfPages method instead! |
PageFormat |
getPageFormat(int pageIndex)
Deprecated. Use the PDPageable adapter class |
Map<String,Integer> |
getPageMap()
This will return the Map containing the mapping from object-ids to pagenumbers. |
Printable |
getPrintable(int pageIndex)
|
SecurityHandler |
getSecurityHandler()
Get the security handler that is used for document encryption. |
PDSignature |
getSignatureDictionary()
|
String |
getUserPasswordForEncryption()
Deprecated. Do not rely on this method anymore. |
PDPage |
importPage(PDPage page)
This will import and copy the contents from another location. |
boolean |
isAllSecurityToBeRemoved()
|
boolean |
isEncrypted()
This will tell if this document is encrypted or not. |
boolean |
isOwnerPassword(String password)
Deprecated. |
boolean |
isUserPassword(String password)
Deprecated. |
static PDDocument |
load(File file)
This will load a document from a file. |
static PDDocument |
load(File file,
RandomAccess scratchFile)
This will load a document from a file. |
static PDDocument |
load(InputStream input)
This will load a document from an input stream. |
static PDDocument |
load(InputStream input,
boolean force)
This will load a document from an input stream. |
static PDDocument |
load(InputStream input,
RandomAccess scratchFile)
This will load a document from an input stream. |
static PDDocument |
load(InputStream input,
RandomAccess scratchFile,
boolean force)
This will load a document from an input stream. |
static PDDocument |
load(String filename)
This will load a document from a file. |
static PDDocument |
load(String filename,
boolean force)
This will load a document from a file. |
static PDDocument |
load(String filename,
RandomAccess scratchFile)
This will load a document from a file. |
static PDDocument |
load(URL url)
This will load a document from a url. |
static PDDocument |
load(URL url,
boolean force)
This will load a document from a url. |
static PDDocument |
load(URL url,
RandomAccess scratchFile)
This will load a document from a url. |
void |
openProtection(DecryptionMaterial pm)
Tries to decrypt the document in memory using the provided decryption material. |
void |
print()
This will send the PDF document to a printer. |
void |
print(PrinterJob printJob)
|
void |
protect(ProtectionPolicy pp)
Protects the document with the protection policy pp. |
boolean |
removePage(int pageNumber)
Remove the page from the document. |
boolean |
removePage(PDPage page)
Remove the page from the document. |
void |
save(OutputStream output)
This will save the document to an output stream. |
void |
save(String fileName)
This will save this document to the filesystem. |
void |
saveIncremental(FileInputStream input,
OutputStream output)
|
void |
saveIncremental(String fileName)
|
void |
setAllSecurityToBeRemoved(boolean allSecurityToBeRemoved)
|
void |
setDocumentInformation(PDDocumentInformation info)
This will set the document information for this document. |
void |
setEncryptionDictionary(PDEncryptionDictionary encDictionary)
This will set the encryption dictionary for this document. |
void |
silentPrint()
This will send the PDF to the default printer without prompting the user for any printer settings. |
void |
silentPrint(PrinterJob printJob)
This will send the PDF to the default printer without prompting the user for any printer settings. |
boolean |
wasDecryptedWithOwnerPassword()
Deprecated. use getCurrentAccessPermission instead |
boolean |
willEncryptWhenSaving()
Deprecated. Do not rely on this method anymore. It is the responsibility of COSWriter to hold this state |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public PDDocument() throws IOException
IOException
- If there is an error creating this document.public PDDocument(COSDocument doc)
doc
- The COSDocument that this document wraps.Method Detail |
---|
public final Map<String,Integer> getPageMap()
public void addPage(PDPage page)
page
- The page to add to the document.public void addSignature(PDSignature sigObject, SignatureInterface signatureInterface) throws IOException, SignatureException
IOException
SignatureException
public void addSignature(PDSignature sigObject, SignatureInterface signatureInterface, SignatureOptions options) throws IOException, SignatureException
sigObject
- is the PDSignature modelsignatureInterface
- is a interface which provides signing capabilitiesoptions
-
IOException
- if there is an error creating required fields
SignatureException
public boolean removePage(PDPage page)
page
- The page to remove from the document.
public boolean 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 PDEncryptionDictionary getEncryptionDictionary() throws IOException
IOException
- If there is an error determining which security handler to use.public void setEncryptionDictionary(PDEncryptionDictionary encDictionary) throws IOException
encDictionary
- The encryption dictionary(most likely a PDStandardEncryption object)
IOException
- If there is an error determining which security handler to use.public PDSignature getSignatureDictionary() throws IOException
IOException
@Deprecated public boolean isUserPassword(String password) throws IOException, CryptographyException
password
- The plain text user password.
IOException
- If there is an error determining if it is the user password.
CryptographyException
- If there is an error in the encryption algorithms.@Deprecated public boolean isOwnerPassword(String password) throws IOException, CryptographyException
password
- The plain text owner password.
IOException
- If there is an error determining if it is the user password.
CryptographyException
- If there is an error in the encryption algorithms.public void decrypt(String password) throws CryptographyException, IOException, InvalidPasswordException
password
- Either the user or owner password.
CryptographyException
- If there is an error decrypting the document.
IOException
- If there is an error getting the stream data.
InvalidPasswordException
- If the password is not a user or owner password.@Deprecated public boolean wasDecryptedWithOwnerPassword()
getCurrentAccessPermission
instead
public void encrypt(String ownerPassword, String userPassword) throws CryptographyException, IOException
ownerPassword
- The owner password to encrypt the document.userPassword
- The user password to encrypt the document.
CryptographyException
- If an error occurs during encryption.
IOException
- If there is an error accessing the data.@Deprecated public String getOwnerPasswordForEncryption()
@Deprecated public String getUserPasswordForEncryption()
@Deprecated public boolean willEncryptWhenSaving()
@Deprecated public void clearWillEncryptWhenSaving()
public static PDDocument load(URL url) throws IOException
url
- The url to load the PDF from.
IOException
- If there is an error reading from the stream.public static PDDocument load(URL url, boolean force) throws IOException
url
- The url to load the PDF from.force
- When true, the parser will skip corrupt pdf objects and
will continue parsing at the next object in the file
IOException
- If there is an error reading from the stream.public static PDDocument load(URL url, RandomAccess scratchFile) throws IOException
url
- The url to load the PDF from.scratchFile
- A location to store temp PDFBox data for this document.
IOException
- If there is an error reading from the stream.public static PDDocument load(String filename) throws IOException
filename
- The name of the file to load.
IOException
- If there is an error reading from the stream.public static PDDocument load(String filename, boolean force) throws IOException
filename
- The name of the file to load.force
- When true, the parser will skip corrupt pdf objects and
will continue parsing at the next object in the file
IOException
- If there is an error reading from the stream.public static PDDocument load(String filename, RandomAccess scratchFile) throws IOException
filename
- The name of the file to load.scratchFile
- A location to store temp PDFBox data for this document.
IOException
- If there is an error reading from the stream.public static PDDocument load(File file) throws IOException
file
- The name of the file to load.
IOException
- If there is an error reading from the stream.public static PDDocument load(File file, RandomAccess scratchFile) throws IOException
file
- The name of the file to load.scratchFile
- A location to store temp PDFBox data for this document.
IOException
- If there is an error reading from the stream.public static PDDocument load(InputStream input) throws IOException
input
- The stream that contains the document.
IOException
- If there is an error reading from the stream.public static PDDocument load(InputStream input, boolean force) throws IOException
input
- The stream that contains the document.force
- When true, the parser will skip corrupt pdf objects and
will continue parsing at the next object in the file
IOException
- If there is an error reading from the stream.public static PDDocument load(InputStream input, RandomAccess scratchFile) throws IOException
input
- The stream that contains the document.scratchFile
- A location to store temp PDFBox data for this document.
IOException
- If there is an error reading from the stream.public static PDDocument load(InputStream input, RandomAccess scratchFile, boolean force) throws IOException
input
- The stream that contains the document.scratchFile
- A location to store temp PDFBox data for this document.force
- When true, the parser will skip corrupt pdf objects and
will continue parsing at the next object in the file
IOException
- If there is an error reading from the stream.public void save(String fileName) throws IOException, COSVisitorException
fileName
- The file to save as.
IOException
- If there is an error saving the document.
COSVisitorException
- If an error occurs while generating the data.public void save(OutputStream output) throws IOException, COSVisitorException
output
- The stream to write to.
IOException
- If there is an error writing the document.
COSVisitorException
- If an error occurs while generating the data.public void saveIncremental(String fileName) throws IOException, COSVisitorException
IOException
COSVisitorException
public void saveIncremental(FileInputStream input, OutputStream output) throws IOException, COSVisitorException
IOException
COSVisitorException
@Deprecated public int getPageCount()
public int getNumberOfPages()
getNumberOfPages
in interface Pageable
@Deprecated public PageFormat getPageFormat(int pageIndex)
PDPageable
adapter class
PrinterJob.getPrinterJob()
.
getPageFormat
in interface Pageable
i
- page index, zero-based
IndexOutOfBoundsException
- if the page index is invalidpublic Printable getPrintable(int pageIndex)
getPrintable
in interface Pageable
public void print(PrinterJob printJob) throws PrinterException
printJob
- The printer job.
PrinterException
- If there is an error while sending the PDF to
the printer, or you do not have permissions to print this document.print()
public void print() throws PrinterException
PrinterException
- If there is an error while sending the PDF to
the printer, or you do not have permissions to print this document.public void silentPrint() throws PrinterException
PrinterException
- If there is an error while printing.print()
public void silentPrint(PrinterJob printJob) throws PrinterException
printJob
- A printer job definition.
PrinterException
- If there is an error while printing.print()
public void close() throws IOException
IOException
- If there is an error releasing resources.public void protect(ProtectionPolicy pp) throws BadSecurityHandlerException
pp
- The protection policy.
BadSecurityHandlerException
- If there is an error during protection.StandardProtectionPolicy
,
PublicKeyProtectionPolicy
public void openProtection(DecryptionMaterial pm) throws BadSecurityHandlerException, IOException, CryptographyException
pm
- The decryption material (password or certificate).
BadSecurityHandlerException
- If there is an error during decryption.
IOException
- If there is an error reading cryptographic information.
CryptographyException
- If there is an error during decryption.StandardDecryptionMaterial
,
PublicKeyDecryptionMaterial
public AccessPermission getCurrentAccessPermission()
public SecurityHandler getSecurityHandler()
public boolean isAllSecurityToBeRemoved()
public void setAllSecurityToBeRemoved(boolean allSecurityToBeRemoved)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |