|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.pdfbox.pdmodel.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!!
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 |
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)
|
Printable |
getPrintable(int pageIndex)
|
SecurityHandler |
getSecurityHandler()
Get the security handler that is used for document encryption. |
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 |
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,
RandomAccess scratchFile)
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,
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,
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 |
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 |
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. |
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 void addPage(PDPage page)
page
- The page to add to the document.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 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.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.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.public String getOwnerPasswordForEncryption()
public String getUserPasswordForEncryption()
public boolean willEncryptWhenSaving()
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, 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, 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, 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 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 int getPageCount()
public int getNumberOfPages()
getNumberOfPages
in interface Pageable
public PageFormat getPageFormat(int pageIndex)
getPageFormat
in interface Pageable
public Printable getPrintable(int pageIndex)
getPrintable
in interface Pageable
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 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()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |