This is the in-memory representation of the PDF document. You need to call
close() on this object when you are done using it!!
author: Ben Litchfield version: $Revision: 1.43 $
Constructor Summary
public
PDDocument() Constructor, creates a new PDF Document with no pages.
load(URL url, RandomAccess scratchFile) This will load a document from a url.
Parameters: url - The url to load the PDF from. Parameters: scratchFile - A location to store temp PDFBox data for this document.
load(String filename, RandomAccess scratchFile) This will load a document from a file.
Parameters: filename - The name of the file to load. Parameters: scratchFile - A location to store temp PDFBox data for this document.
load(File file, RandomAccess scratchFile) This will load a document from a file.
Parameters: file - The name of the file to load. Parameters: scratchFile - A location to store temp PDFBox data for this document.
load(InputStream input, RandomAccess scratchFile) This will load a document from an input stream.
Parameters: input - The stream that contains the document. Parameters: scratchFile - A location to store temp PDFBox data for this document.
Constructor, creates a new PDF Document with no pages. You need to add
at least one page for the document to be valid.
throws: IOException - If there is an error creating this document.
Constructor that uses an existing document. The COSDocument that
is passed in must be valid.
Parameters: doc - The COSDocument that this document wraps.
This will add a page to the document. This is a convenience method, that
will add the page to the root of the hierarchy and set the parent of the
page to the root.
Parameters: page - The page to add to the document.
This will decrypt a document. This method is provided for compatibility reasons only. User should use
the new security layer instead and the openProtection method especially.
Parameters: password - Either the user or owner password. throws: CryptographyException - If there is an error decrypting the document. throws: IOException - If there is an error getting the stream data. throws: InvalidPasswordException - If the password is not a user or owner password.
This will mark a document to be encrypted. The actual encryption
will occur when the document is saved.
This method is provided for compatibility reasons only. User should use
the new security layer instead and the openProtection method especially.
Parameters: ownerPassword - The owner password to encrypt the document. Parameters: userPassword - The user password to encrypt the document. throws: CryptographyException - If an error occurs during encryption. throws: IOException - If there is an error accessing the data.
Returns the access permissions granted when the document was decrypted.
If the document was not decrypted this method returns the access permission
for a document owner (ie can do everything).
The returned object is in read only mode so that permissions cannot be changed.
Methods providing access to content should rely on this object to verify if the current
user is allowed to proceed.
the access permissions for the current user on the document.
This will get the encryption dictionary for this document. This will still
return the parameters if the document was decrypted. If the document was
never encrypted then this will return null. As the encryption architecture
in PDF documents is plugable this returns an abstract class, but the only
supported subclass at this time is a PDStandardEncryption object.
The encryption dictionary(most likely a PDStandardEncryption object) throws: IOException - If there is an error determining which security handler to use.
The owner password that was passed into the encrypt method. You should
never use this method. This will not longer be valid once encryption
has occured.
The owner password passed to the encrypt method.
This will return the total page count of the PDF document. Note: This method
is deprecated in favor of the getNumberOfPages method. The getNumberOfPages is
a required interface method of the Pageable interface. This method will
be removed in a future version of PDFBox!!
The total number of pages in the PDF document.
The user password that was passed into the encrypt method. You should
never use this method. This will not longer be valid once encryption
has occured.
The user password passed to the encrypt method.
This will import and copy the contents from another location. Currently
the content stream is stored in a scratch file. The scratch file is
associated with the document. If you are adding a page to this document
from another document and want to copy the contents to this document's
scratch file then use this method otherwise just use the addPage method.
Parameters: page - The page to import. The page that was imported. throws: IOException - If there is an error copying the page.
This will determine if this is the owner password. This only applies when
the document is encrypted and uses standard encryption.
Parameters: password - The plain text owner password. true If the password passed in matches the owner password used to encrypt the document. throws: IOException - If there is an error determining if it is the user password. throws: CryptographyException - If there is an error in the encryption algorithms.
This will determine if this is the user password. This only applies when
the document is encrypted and uses standard encryption.
Parameters: password - The plain text user password. true If the password passed in matches the user password used to encrypt the document. throws: IOException - If there is an error determining if it is the user password. throws: CryptographyException - If there is an error in the encryption algorithms.
This will load a document from a url.
Parameters: url - The url to load the PDF from. The document that was loaded. throws: IOException - If there is an error reading from the stream.
This will load a document from a url.
Parameters: url - The url to load the PDF from. Parameters: scratchFile - A location to store temp PDFBox data for this document. The document that was loaded. throws: IOException - If there is an error reading from the stream.
This will load a document from a file.
Parameters: filename - The name of the file to load. The document that was loaded. throws: IOException - If there is an error reading from the stream.
This will load a document from a file.
Parameters: filename - The name of the file to load. Parameters: scratchFile - A location to store temp PDFBox data for this document. The document that was loaded. throws: IOException - If there is an error reading from the stream.
This will load a document from a file.
Parameters: file - The name of the file to load. The document that was loaded. throws: IOException - If there is an error reading from the stream.
This will load a document from a file.
Parameters: file - The name of the file to load. Parameters: scratchFile - A location to store temp PDFBox data for this document. The document that was loaded. throws: IOException - If there is an error reading from the stream.
This will load a document from an input stream.
Parameters: input - The stream that contains the document. The document that was loaded. throws: IOException - If there is an error reading from the stream.
This will load a document from an input stream.
Parameters: input - The stream that contains the document. Parameters: scratchFile - A location to store temp PDFBox data for this document. The document that was loaded. throws: IOException - If there is an error reading from the stream.
This will send the PDF document to a printer. The printing functionality
depends on the org.pdfbox.pdfviewer.PageDrawer functionality. The PageDrawer
is a work in progress and some PDFs will print correctly and some will
not. This is a convenience method to create the java.awt.print.PrinterJob.
The PDDocument implements the java.awt.print.Pageable interface and
PDPage implementes the java.awt.print.Printable interface, so advanced printing
capabilities can be done by using those interfaces instead of this method.
throws: PrinterException - If there is an error while sending the PDF tothe printer, or you do not have permissions to print this document.
This will save this document to the filesystem.
Parameters: fileName - The file to save as. throws: IOException - If there is an error saving the document. throws: COSVisitorException - If an error occurs while generating the data.
This will save the document to an output stream.
Parameters: output - The stream to write to. throws: IOException - If there is an error writing the document. throws: COSVisitorException - If an error occurs while generating the data.
This will set the encryption dictionary for this document.
Parameters: encDictionary - The encryption dictionary(most likely a PDStandardEncryption object) throws: IOException - If there is an error determining which security handler to use.
This will send the PDF to the default printer without prompting the user
for any printer settings.
See Also:PDDocument.print throws: PrinterException - If there is an error while printing.
wasDecryptedWithOwnerPassword
public boolean wasDecryptedWithOwnerPassword()(Code)
This will tell if the document was decrypted with the master password. This
entry is invalid if the PDF was not decrypted.
true if the pdf was decrypted with the master password.
Internal method do determine if the document will be encrypted when it is saved.
True if encrypt has been called and the document has not been saved yet.