Home » pdfbox-1.1.0-src » org.apache.pdfbox.pdmodel » [javadoc | source]
org.apache.pdfbox.pdmodel
public class: PDDocument [javadoc | source]
java.lang.Object
   org.apache.pdfbox.pdmodel.PDDocument

All Implemented Interfaces:
    Pageable

This is the in-memory representation of the PDF document. You need to call close() on this object when you are done using it!!
Constructor:
 public PDDocument() throws IOException 
    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.
 public PDDocument(COSDocument doc) 
    Constructor that uses an existing document. The COSDocument that is passed in must be valid.
    Parameters:
    doc - The COSDocument that this document wraps.
Method from org.apache.pdfbox.pdmodel.PDDocument Summary:
addPage,   clearWillEncryptWhenSaving,   close,   decrypt,   encrypt,   getCurrentAccessPermission,   getDocument,   getDocumentCatalog,   getDocumentInformation,   getEncryptionDictionary,   getNumberOfPages,   getOwnerPasswordForEncryption,   getPageCount,   getPageFormat,   getPageMap,   getPrintable,   getSecurityHandler,   getUserPasswordForEncryption,   importPage,   isAllSecurityToBeRemoved,   isEncrypted,   isOwnerPassword,   isUserPassword,   load,   load,   load,   load,   load,   load,   load,   load,   load,   load,   load,   load,   openProtection,   print,   print,   protect,   removePage,   removePage,   save,   save,   setAllSecurityToBeRemoved,   setDocumentInformation,   setEncryptionDictionary,   silentPrint,   silentPrint,   wasDecryptedWithOwnerPassword,   willEncryptWhenSaving
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.apache.pdfbox.pdmodel.PDDocument Detail:
 public  void addPage(PDPage page) 
    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.
 public  void clearWillEncryptWhenSaving() 
Deprecated! Do - not rely on this method anymore. It is the responsability of COSWriter to hold this state.

    This shoule only be called by the COSWriter after encryption has completed.
 public  void close() throws IOException 
    This will close the underlying COSDocument object.
 public  void decrypt(String password) throws CryptographyException, IOException, InvalidPasswordException 
    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.
 public  void encrypt(String ownerPassword,
    String userPassword) throws CryptographyException, IOException 
    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.
 public AccessPermission getCurrentAccessPermission() 
    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.
 public COSDocument getDocument() 
    This will get the low level document.
 public PDDocumentCatalog getDocumentCatalog() 
    This will get the document CATALOG. This is guaranteed to not return null.
 public PDDocumentInformation getDocumentInformation() 
    This will get the document info dictionary. This is guaranteed to not return null.
 public PDEncryptionDictionary getEncryptionDictionary() throws IOException 
    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.
 public int getNumberOfPages() 
    {@inheritDoc}
 public String getOwnerPasswordForEncryption() 
Deprecated! Do - not rely on this method anymore.

    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.
 public int getPageCount() 
Deprecated! Use - the getNumberOfPages method instead!

    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!!
 public PageFormat getPageFormat(int pageIndex) 
    {@inheritDoc}
 public final Map getPageMap() 
    This will return the Map containing the mapping from object-ids to pagenumbers.
 public Printable getPrintable(int pageIndex) 
    {@inheritDoc}
 public SecurityHandler getSecurityHandler() 
    Get the security handler that is used for document encryption.
 public String getUserPasswordForEncryption() 
Deprecated! Do - not rely on this method anymore.

    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.
 public PDPage importPage(PDPage page) throws IOException 
    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.
 public boolean isAllSecurityToBeRemoved() 
 public boolean isEncrypted() 
    This will tell if this document is encrypted or not.
 public boolean isOwnerPassword(String password) throws IOException, CryptographyException 
Deprecated!
    This will determine if this is the owner password. This only applies when the document is encrypted and uses standard encryption.
 public boolean isUserPassword(String password) throws IOException, CryptographyException 
Deprecated!
    This will determine if this is the user password. This only applies when the document is encrypted and uses standard encryption.
 public static PDDocument load(URL url) throws IOException 
    This will load a document from a url.
 public static PDDocument load(String filename) throws IOException 
    This will load a document from a file.
 public static PDDocument load(File file) throws IOException 
    This will load a document from a file.
 public static PDDocument load(InputStream input) throws IOException 
    This will load a document from an input stream.
 public static PDDocument load(URL url,
    boolean force) throws IOException 
    This will load a document from a url. Used for skipping corrupt pdf objects
 public static PDDocument load(URL url,
    RandomAccess scratchFile) throws IOException 
    This will load a document from a url.
 public static PDDocument load(String filename,
    boolean force) throws IOException 
    This will load a document from a file. Allows for skipping corrupt pdf objects
 public static PDDocument load(String filename,
    RandomAccess scratchFile) throws IOException 
    This will load a document from a file.
 public static PDDocument load(File file,
    RandomAccess scratchFile) throws IOException 
    This will load a document from a file.
 public static PDDocument load(InputStream input,
    boolean force) throws IOException 
    This will load a document from an input stream. Allows for skipping corrupt pdf objects
 public static PDDocument load(InputStream input,
    RandomAccess scratchFile) throws IOException 
    This will load a document from an input stream.
 public static PDDocument load(InputStream input,
    RandomAccess scratchFile,
    boolean force) throws IOException 
    This will load a document from an input stream. Allows for skipping corrupt pdf objects
 public  void openProtection(DecryptionMaterial pm) throws BadSecurityHandlerException, IOException, CryptographyException 
    Tries to decrypt the document in memory using the provided decryption material.
 public  void print() throws PrinterException 
    This will send the PDF document to a printer. The printing functionality depends on the org.apache.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.
 public  void print(PrinterJob printJob) throws PrinterException 
 public  void protect(ProtectionPolicy pp) throws BadSecurityHandlerException 
    Protects the document with the protection policy pp. The document content will be really encrypted when it will be saved. This method only marks the document for encryption.
 public boolean removePage(PDPage page) 
    Remove the page from the document.
 public boolean removePage(int pageNumber) 
    Remove the page from the document.
 public  void save(String fileName) throws IOException, COSVisitorException 
    This will save this document to the filesystem.
 public  void save(OutputStream output) throws IOException, COSVisitorException 
    This will save the document to an output stream.
 public  void setAllSecurityToBeRemoved(boolean allSecurityToBeRemoved) 
 public  void setDocumentInformation(PDDocumentInformation info) 
    This will set the document information for this document.
 public  void setEncryptionDictionary(PDEncryptionDictionary encDictionary) throws IOException 
    This will set the encryption dictionary for this document.
 public  void silentPrint() throws PrinterException 
    This will send the PDF to the default printer without prompting the user for any printer settings.
 public  void silentPrint(PrinterJob printJob) throws PrinterException 
    This will send the PDF to the default printer without prompting the user for any printer settings.
 public boolean wasDecryptedWithOwnerPassword() 
Deprecated! use - getCurrentAccessPermission instead

    This will tell if the document was decrypted with the master password. This entry is invalid if the PDF was not decrypted.
 public boolean willEncryptWhenSaving() 
Deprecated! Do - not rely on this method anymore. It is the responsibility of COSWriter to hold this state

    Internal method do determine if the document will be encrypted when it is saved.