pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1515127 [2/3] - in /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox: PDFReader.java PrintPDF.java pdmodel/PDDocument.java pdmodel/PDPage.java pdmodel/PDPageable.java util/PDFImageWriter.java util/RenderUtil.java
Date Sun, 18 Aug 2013 15:02:08 GMT
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java?rev=1515127&r1=1515126&r2=1515127&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java Sun Aug 18 15:02:07 2013
@@ -16,11 +16,6 @@
  */
 package org.apache.pdfbox.pdmodel;
 
-import java.awt.print.PageFormat;
-import java.awt.print.Pageable;
-import java.awt.print.Printable;
-import java.awt.print.PrinterException;
-import java.awt.print.PrinterJob;
 import java.io.BufferedInputStream;
 import java.io.Closeable;
 import java.io.File;
@@ -75,28 +70,24 @@ import org.apache.pdfbox.pdmodel.interac
 import org.apache.pdfbox.pdmodel.interactive.form.PDSignatureField;
 
 /**
- * This is the in-memory representation of the PDF document.  You need to call
- * close() on this object when you are done using it!!
- * <p>
- * This class implements the {@link Pageable} interface, but since PDFBox
- * version 1.3.0 you should be using the {@link PDPageable} adapter instead
- * (see <a href="https://issues.apache.org/jira/browse/PDFBOX-788">PDFBOX-788</a>).
- *
+ * 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 <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
- * @version $Revision: 1.47 $
+ * 
  */
-public class PDDocument implements Pageable, Closeable
+public class PDDocument implements Closeable
 {
 
     private COSDocument document;
 
-    //cached values
+    // cached values
     private PDDocumentInformation documentInformation;
     private PDDocumentCatalog documentCatalog;
-    
-    //The encParameters will be cached here.  When the document is decrypted then
-    //the COSDocument will not have an "Encrypt" dictionary anymore and this object
-    //must be used.
+
+    // The encParameters will be cached here. When the document is decrypted then
+    // the COSDocument will not have an "Encrypt" dictionary anymore and this object
+    // must be used.
     private PDEncryptionDictionary encParameters = null;
 
     /**
@@ -104,152 +95,147 @@ public class PDDocument implements Pagea
      */
     private SecurityHandler securityHandler = null;
 
-
     /**
-     * This assocates object ids with a page number.  It's used to determine
-     * the page number for bookmarks (or page numbers for anything else for
-     * which you have an object id for that matter). 
+     * This assocates object ids with a page number. It's used to determine the page number for bookmarks (or page
+     * numbers for anything else for which you have an object id for that matter).
      */
     private Map<String, Integer> pageMap = null;
-    
+
     /**
-     * This will hold a flag which tells us if we should remove all security
-     * from this documents.
+     * This will hold a flag which tells us if we should remove all security from this documents.
      */
     private boolean allSecurityToBeRemoved = false;
 
     /**
-     * Keep tracking customized documentId for the trailer. If null, a new 
-     * id will be generated for the document. This ID doesn't represent the
-     * actual documentId from the trailer.
+     * Keep tracking customized documentId for the trailer. If null, a new id will be generated for the document. This
+     * ID doesn't represent the actual documentId from the trailer.
      */
     private Long documentId;
 
-    
     /**
-     * Constructor, creates a new PDF Document with no pages.  You need to add
-     * at least one page for the document to be valid.
-     *
+     * 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() throws IOException
     {
         document = new COSDocument();
 
-        //First we need a trailer
+        // First we need a trailer
         COSDictionary trailer = new COSDictionary();
-        document.setTrailer( trailer );
+        document.setTrailer(trailer);
 
-        //Next we need the root dictionary.
+        // Next we need the root dictionary.
         COSDictionary rootDictionary = new COSDictionary();
-        trailer.setItem( COSName.ROOT, rootDictionary );
-        rootDictionary.setItem( COSName.TYPE, COSName.CATALOG );
-        rootDictionary.setItem( COSName.VERSION, COSName.getPDFName( "1.4" ) );
+        trailer.setItem(COSName.ROOT, rootDictionary);
+        rootDictionary.setItem(COSName.TYPE, COSName.CATALOG);
+        rootDictionary.setItem(COSName.VERSION, COSName.getPDFName("1.4"));
 
-        //next we need the pages tree structure
+        // next we need the pages tree structure
         COSDictionary pages = new COSDictionary();
-        rootDictionary.setItem( COSName.PAGES, pages );
-        pages.setItem( COSName.TYPE, COSName.PAGES );
+        rootDictionary.setItem(COSName.PAGES, pages);
+        pages.setItem(COSName.TYPE, COSName.PAGES);
         COSArray kidsArray = new COSArray();
-        pages.setItem( COSName.KIDS, kidsArray );
-        pages.setItem( COSName.COUNT, COSInteger.ZERO );
+        pages.setItem(COSName.KIDS, kidsArray);
+        pages.setItem(COSName.COUNT, COSInteger.ZERO);
     }
 
-    private void generatePageMap() 
+    private void generatePageMap()
     {
-        pageMap = new HashMap<String,Integer>();
-        // these page nodes could be references to pages, 
+        pageMap = new HashMap<String, Integer>();
+        // these page nodes could be references to pages,
         // or references to arrays which have references to pages
         // or references to arrays which have references to arrays which have references to pages
         // or ... (I think you get the idea...)
         processListOfPageReferences(getDocumentCatalog().getPages().getKids());
     }
-    
+
     private void processListOfPageReferences(List<Object> pageNodes)
     {
         int numberOfNodes = pageNodes.size();
-        for(int i=0; i < numberOfNodes; ++i) 
+        for (int i = 0; i < numberOfNodes; ++i)
         {
             Object pageOrArray = pageNodes.get(i);
-            if(pageOrArray instanceof PDPage)
+            if (pageOrArray instanceof PDPage)
             {
-                COSArray pageArray = ((COSArrayList)(((PDPage)pageOrArray).getParent()).getKids()).toList();
-                parseCatalogObject((COSObject)pageArray.get(i));
+                COSArray pageArray = ((COSArrayList) (((PDPage) pageOrArray).getParent()).getKids()).toList();
+                parseCatalogObject((COSObject) pageArray.get(i));
             }
-            else if(pageOrArray instanceof PDPageNode)
+            else if (pageOrArray instanceof PDPageNode)
             {
-                processListOfPageReferences(((PDPageNode)pageOrArray).getKids());
+                processListOfPageReferences(((PDPageNode) pageOrArray).getKids());
             }
         }
     }
-             
+
     /**
-     * This will either add the page passed in, or, if it's a pointer to an array
-     * of pages, it'll recursivly call itself and process everything in the list.
+     * This will either add the page passed in, or, if it's a pointer to an array of pages, it'll recursivly call itself
+     * and process everything in the list.
      */
-    private void parseCatalogObject(COSObject thePageOrArrayObject) 
+    private void parseCatalogObject(COSObject thePageOrArrayObject)
     {
         COSBase arrayCountBase = thePageOrArrayObject.getItem(COSName.COUNT);
         int arrayCount = -1;
-        if(arrayCountBase instanceof COSInteger)
+        if (arrayCountBase instanceof COSInteger)
         {
-            arrayCount = ((COSInteger)arrayCountBase).intValue();
+            arrayCount = ((COSInteger) arrayCountBase).intValue();
         }
- 
+
         COSBase kidsBase = thePageOrArrayObject.getItem(COSName.KIDS);
         int kidsCount = -1;
-        if(kidsBase instanceof COSArray)
+        if (kidsBase instanceof COSArray)
         {
-            kidsCount = ((COSArray)kidsBase).size();
+            kidsCount = ((COSArray) kidsBase).size();
         }
-     
-        if(arrayCount == -1 || kidsCount == -1) 
+
+        if (arrayCount == -1 || kidsCount == -1)
         {
             // these cases occur when we have a page, not an array of pages
             String objStr = String.valueOf(thePageOrArrayObject.getObjectNumber().intValue());
             String genStr = String.valueOf(thePageOrArrayObject.getGenerationNumber().intValue());
-            getPageMap().put(objStr+","+genStr, new Integer(getPageMap().size()+1));
-        } 
-        else 
+            getPageMap().put(objStr + "," + genStr, new Integer(getPageMap().size() + 1));
+        }
+        else
         {
             // we either have an array of page pointers, or an array of arrays
-            if(arrayCount == kidsCount) 
+            if (arrayCount == kidsCount)
             {
                 // process the kids... they're all references to pages
-                COSArray kidsArray = ((COSArray)kidsBase);
-                for(int i=0; i<kidsArray.size(); ++i) 
+                COSArray kidsArray = ((COSArray) kidsBase);
+                for (int i = 0; i < kidsArray.size(); ++i)
                 {
-                    COSObject thisObject = (COSObject)kidsArray.get(i);
+                    COSObject thisObject = (COSObject) kidsArray.get(i);
                     String objStr = String.valueOf(thisObject.getObjectNumber().intValue());
                     String genStr = String.valueOf(thisObject.getGenerationNumber().intValue());
-                    getPageMap().put(objStr+","+genStr, new Integer(getPageMap().size()+1));
+                    getPageMap().put(objStr + "," + genStr, new Integer(getPageMap().size() + 1));
                 }
-            } 
-            else 
+            }
+            else
             {
                 // this object is an array of references to other arrays
                 COSArray list = null;
-                if(kidsBase instanceof COSArray)
+                if (kidsBase instanceof COSArray)
                 {
-                    list = ((COSArray)kidsBase);
+                    list = ((COSArray) kidsBase);
                 }
-                if(list != null) 
+                if (list != null)
                 {
-                    for(int arrayCounter=0; arrayCounter < list.size(); ++arrayCounter) 
+                    for (int arrayCounter = 0; arrayCounter < list.size(); ++arrayCounter)
                     {
-                        parseCatalogObject((COSObject)list.get(arrayCounter));
+                        parseCatalogObject((COSObject) list.get(arrayCounter));
                     }
                 }
             }
         }
     }
- 
+
     /**
      * This will return the Map containing the mapping from object-ids to pagenumbers.
      * 
      * @return the pageMap
      */
-    public final Map<String,Integer> getPageMap() 
+    public final Map<String, Integer> getPageMap()
     {
         if (pageMap == null)
         {
@@ -259,17 +245,16 @@ public class PDDocument implements Pagea
     }
 
     /**
-     * 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.
-     *
+     * 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.
+     * 
      * @param page The page to add to the document.
      */
-    public void addPage( PDPage page )
+    public void addPage(PDPage page)
     {
         PDPageNode rootPages = getDocumentCatalog().getPages();
-        rootPages.getKids().add( page );
-        page.setParent( rootPages );
+        rootPages.getKids().add(page);
+        page.setParent(rootPages);
         rootPages.updateCount();
     }
 
@@ -281,17 +266,17 @@ public class PDDocument implements Pagea
      * @throws IOException if there is an error creating required fields
      * @throws SignatureException if something went wrong
      */
-    public void addSignature(PDSignature sigObject, SignatureInterface signatureInterface) 
-            throws IOException, SignatureException
+    public void addSignature(PDSignature sigObject, SignatureInterface signatureInterface) throws IOException,
+            SignatureException
     {
         SignatureOptions defaultOptions = new SignatureOptions();
         defaultOptions.setPage(1);
-        addSignature(sigObject, signatureInterface,defaultOptions);
+        addSignature(sigObject, signatureInterface, defaultOptions);
     }
-    
+
     /**
-     * This will add a signature to the document. 
-     *
+     * This will add a signature to the document.
+     * 
      * @param sigObject is the PDSignature model
      * @param signatureInterface is a interface which provides signing capabilities
      * @param options signature options
@@ -313,15 +298,15 @@ public class PDDocument implements Pagea
         {
             sigObject.setContents(new byte[0x2500 * 2 + 2]);
         }
-        
+
         // Reserve ByteRange
-        sigObject.setByteRange(new int[] {0,1000000000,1000000000,1000000000});
-      
+        sigObject.setByteRange(new int[] { 0, 1000000000, 1000000000, 1000000000 });
+
         getDocument().setSignatureInterface(signatureInterface);
-      
+
         // #########################################
-        // # Create SignatureForm for signature    #
-        // # and appending it to the document      #
+        // # Create SignatureForm for signature #
+        // # and appending it to the document #
         // #########################################
 
         // Get the first page
@@ -329,45 +314,45 @@ public class PDDocument implements Pagea
         PDPageNode rootPages = root.getPages();
         List<PDPage> kids = new ArrayList<PDPage>();
         rootPages.getAllKids(kids);
-  
-        int size = (int)rootPages.getCount();
+
+        int size = (int) rootPages.getCount();
         PDPage page = null;
         if (size == 0)
         {
             throw new SignatureException(SignatureException.INVALID_PAGE_FOR_SIGNATURE, "The PDF file has no pages");
         }
-        if (options.getPage()>size)
+        if (options.getPage() > size)
         {
-            page = kids.get(size-1);
+            page = kids.get(size - 1);
         }
-        else if(options.getPage()<=0)
+        else if (options.getPage() <= 0)
         {
             page = kids.get(0);
         }
         else
         {
-            page = kids.get(options.getPage()-1);
+            page = kids.get(options.getPage() - 1);
         }
 
         // Get the AcroForm from the Root-Dictionary and append the annotation
         PDAcroForm acroForm = root.getAcroForm();
-        root.getCOSObject().setNeedToBeUpdate(true); 
-        
-        if (acroForm==null) 
+        root.getCOSObject().setNeedToBeUpdate(true);
+
+        if (acroForm == null)
         {
             acroForm = new PDAcroForm(this);
             root.setAcroForm(acroForm);
-        } 
-        else 
+        }
+        else
         {
             acroForm.getCOSObject().setNeedToBeUpdate(true);
         }
-      
+
         /*
-         * For invisible signatures, the annotation has a rectangle array with values [ 0 0 0 0 ]. 
-         * This annotation is usually attached to the viewed page when the signature is created. 
-         * Despite not having an appearance, the annotation AP and N dictionaries may be present 
-         * in some versions of Acrobat. If present, N references the DSBlankXObj (blank) XObject.
+         * For invisible signatures, the annotation has a rectangle array with values [ 0 0 0 0 ]. This annotation is
+         * usually attached to the viewed page when the signature is created. Despite not having an appearance, the
+         * annotation AP and N dictionaries may be present in some versions of Acrobat. If present, N references the
+         * DSBlankXObj (blank) XObject.
          */
 
         // Create Annotation / Field for signature
@@ -375,36 +360,36 @@ public class PDDocument implements Pagea
 
         List<PDField> fields = acroForm.getFields();
         PDSignatureField signatureField = null;
-        for ( PDField pdField : fields )
+        for (PDField pdField : fields)
         {
             if (pdField instanceof PDSignatureField)
             {
-                PDSignature signature = ((PDSignatureField)pdField).getSignature();
+                PDSignature signature = ((PDSignatureField) pdField).getSignature();
                 if (signature != null && signature.getDictionary().equals(sigObject.getDictionary()))
                 {
-                    signatureField = (PDSignatureField)pdField;
+                    signatureField = (PDSignatureField) pdField;
                 }
             }
         }
         if (signatureField == null)
         {
             signatureField = new PDSignatureField(acroForm);
-            signatureField.setSignature(sigObject);              // append the signature object
-            signatureField.getWidget().setPage(page);            // backward linking
+            signatureField.setSignature(sigObject); // append the signature object
+            signatureField.getWidget().setPage(page); // backward linking
         }
-        
+
         // Set the AcroForm Fields
         List<PDField> acroFormFields = acroForm.getFields();
         COSDictionary acroFormDict = acroForm.getDictionary();
         acroFormDict.setDirect(true);
         acroFormDict.setInt(COSName.SIG_FLAGS, 3);
-        
+
         boolean checkFields = false;
-        for ( PDField field : acroFormFields )
+        for (PDField field : acroFormFields)
         {
             if (field instanceof PDSignatureField)
             {
-                if (((PDSignatureField)field).getCOSObject().equals(signatureField.getCOSObject()))
+                if (((PDSignatureField) field).getCOSObject().equals(signatureField.getCOSObject()))
                 {
                     checkFields = true;
                     signatureField.getCOSObject().setNeedToBeUpdate(true);
@@ -416,7 +401,7 @@ public class PDDocument implements Pagea
         {
             acroFormFields.add(signatureField);
         }
-        
+
         // Get the object from the visual signature
         COSDocument visualSignature = options.getVisualSignature();
 
@@ -424,7 +409,7 @@ public class PDDocument implements Pagea
         if (visualSignature == null) // non-visual signature
         {
             // Set rectangle for non-visual signature to 0 0 0 0
-            signatureField.getWidget().setRectangle(new PDRectangle());  // rectangle array [ 0 0 0 0 ]
+            signatureField.getWidget().setRectangle(new PDRectangle()); // rectangle array [ 0 0 0 0 ]
             // Clear AcroForm / Set DefaultRessource
             acroFormDict.setItem(COSName.DR, null);
             // Set empty Appearance-Dictionary
@@ -432,87 +417,86 @@ public class PDDocument implements Pagea
             COSStream apsStream = getDocument().createCOSStream();
             apsStream.createUnfilteredStream();
             PDAppearanceStream aps = new PDAppearanceStream(apsStream);
-            COSDictionary cosObject = (COSDictionary)aps.getCOSObject();
+            COSDictionary cosObject = (COSDictionary) aps.getCOSObject();
             cosObject.setItem(COSName.SUBTYPE, COSName.FORM);
             cosObject.setItem(COSName.BBOX, new PDRectangle());
-            
+
             ap.setNormalAppearance(aps);
             ap.getDictionary().setDirect(true);
             signatureField.getWidget().setAppearance(ap);
         }
-        else // visual signature
+        else
+        // visual signature
         {
             // Obtain visual signature object
             List<COSObject> cosObjects = visualSignature.getObjects();
-    
+
             boolean annotNotFound = true;
             boolean sigFieldNotFound = true;
 
-            for ( COSObject cosObject : cosObjects )
+            for (COSObject cosObject : cosObjects)
             {
                 if (!annotNotFound && !sigFieldNotFound)
                 {
                     break;
                 }
-                
+
                 COSBase base = cosObject.getObject();
                 if (base != null && base instanceof COSDictionary)
                 {
-                    COSBase ft = ((COSDictionary)base).getItem(COSName.FT);
-                    COSBase type = ((COSDictionary)base).getItem(COSName.TYPE);
-                    COSBase apDict = ((COSDictionary)base).getItem(COSName.AP);
-            
+                    COSBase ft = ((COSDictionary) base).getItem(COSName.FT);
+                    COSBase type = ((COSDictionary) base).getItem(COSName.TYPE);
+                    COSBase apDict = ((COSDictionary) base).getItem(COSName.AP);
+
                     // Search for signature annotation
                     if (annotNotFound && COSName.ANNOT.equals(type))
                     {
-                        COSDictionary cosBaseDict = (COSDictionary)base;
-              
+                        COSDictionary cosBaseDict = (COSDictionary) base;
+
                         // Read and set the Rectangle for visual signature
-                        COSArray rectAry = (COSArray)cosBaseDict.getItem(COSName.RECT);
+                        COSArray rectAry = (COSArray) cosBaseDict.getItem(COSName.RECT);
                         PDRectangle rect = new PDRectangle(rectAry);
                         signatureField.getWidget().setRectangle(rect);
                         annotNotFound = false;
                     }
-            
+
                     // Search for Signature-Field
                     if (sigFieldNotFound && COSName.SIG.equals(ft) && apDict != null)
                     {
-                        COSDictionary cosBaseDict = (COSDictionary)base;
-              
+                        COSDictionary cosBaseDict = (COSDictionary) base;
+
                         // Appearance Dictionary auslesen und setzen
-                        PDAppearanceDictionary ap = 
-                                new PDAppearanceDictionary((COSDictionary)cosBaseDict.getItem(COSName.AP));
+                        PDAppearanceDictionary ap = new PDAppearanceDictionary(
+                                (COSDictionary) cosBaseDict.getItem(COSName.AP));
                         ap.getDictionary().setDirect(true);
                         signatureField.getWidget().setAppearance(ap);
-              
+
                         // AcroForm DefaultRessource auslesen und setzen
                         COSBase dr = cosBaseDict.getItem(COSName.DR);
                         dr.setDirect(true);
                         dr.setNeedToBeUpdate(true);
                         acroFormDict.setItem(COSName.DR, dr);
-                        sigFieldNotFound=false;
+                        sigFieldNotFound = false;
                     }
                 }
             }
-        
-            if (annotNotFound || sigFieldNotFound )
+
+            if (annotNotFound || sigFieldNotFound)
             {
-                throw new SignatureException(SignatureException.VISUAL_SIGNATURE_INVALID, 
+                throw new SignatureException(SignatureException.VISUAL_SIGNATURE_INVALID,
                         "Could not read all needed objects from template");
             }
         }
-      
+
         // Get the annotations of the page and append the signature-annotation to it
-        if (annotations == null) 
+        if (annotations == null)
         {
             annotations = new COSArrayList();
             page.setAnnotations(annotations);
         }
         // take care that page and acroforms do not share the same array (if so, we don't need to add it twice)
-        if (!((annotations instanceof COSArrayList) 
-                && (acroFormFields instanceof COSArrayList) 
-                && (((COSArrayList)annotations).toList().equals(((COSArrayList)acroFormFields).toList())))
-                && !checkFields)
+        if (!((annotations instanceof COSArrayList) && (acroFormFields instanceof COSArrayList) && (((COSArrayList) annotations)
+                .toList().equals(((COSArrayList) acroFormFields).toList()))) && !checkFields)
         {
             annotations.add(signatureField.getWidget());
         }
@@ -521,15 +505,15 @@ public class PDDocument implements Pagea
 
     /**
      * This will add a signaturefield to the document.
+     * 
      * @param sigFields are the PDSignatureFields that should be added to the document
      * @param signatureInterface is a interface which provides signing capabilities
      * @param options signature options
      * @throws IOException if there is an error creating required fields
-     * @throws SignatureException 
+     * @throws SignatureException
      */
-    public void addSignatureField(List<PDSignatureField> sigFields,
-                                  SignatureInterface signatureInterface,
-                                  SignatureOptions options) throws IOException, SignatureException
+    public void addSignatureField(List<PDSignatureField> sigFields, SignatureInterface signatureInterface,
+            SignatureOptions options) throws IOException, SignatureException
     {
         PDDocumentCatalog catalog = getDocumentCatalog();
         catalog.getCOSObject().setNeedToBeUpdate(true);
@@ -555,26 +539,26 @@ public class PDDocument implements Pagea
 
         List<PDField> field = acroForm.getFields();
 
-        for ( PDSignatureField sigField : sigFields )
+        for (PDSignatureField sigField : sigFields)
         {
             PDSignature sigObject = sigField.getSignature();
             sigField.getCOSObject().setNeedToBeUpdate(true);
 
             // Check if the field already exist
             boolean checkFields = false;
-            for ( Object obj : field )
+            for (Object obj : field)
             {
                 if (obj instanceof PDSignatureField)
                 {
-                    if (((PDSignatureField)obj).getCOSObject().equals(sigField.getCOSObject()))
+                    if (((PDSignatureField) obj).getCOSObject().equals(sigField.getCOSObject()))
                     {
-                        checkFields=true;
+                        checkFields = true;
                         sigField.getCOSObject().setNeedToBeUpdate(true);
                         break;
                     }
                 }
             }
-            
+
             if (!checkFields)
             {
                 field.add(sigField);
@@ -593,21 +577,20 @@ public class PDDocument implements Pagea
         }
     }
 
-    
     /**
      * Remove the page from the document.
-     *
+     * 
      * @param page The page to remove from the document.
-     *
+     * 
      * @return true if the page was found false otherwise.
      */
-    public boolean removePage( PDPage page )
+    public boolean removePage(PDPage page)
     {
         PDPageNode parent = page.getParent();
-        boolean retval = parent.getKids().remove( page );
-        if( retval )
+        boolean retval = parent.getKids().remove(page);
+        if (retval)
         {
-            //do a recursive updateCount starting at the root of the document
+            // do a recursive updateCount starting at the root of the document
             getDocumentCatalog().getPages().updateCount();
         }
         return retval;
@@ -615,65 +598,64 @@ public class PDDocument implements Pagea
 
     /**
      * Remove the page from the document.
-     *
+     * 
      * @param pageNumber 0 based index to page number.
      * @return true if the page was found false otherwise.
      */
-    public boolean removePage( int pageNumber )
+    public boolean removePage(int pageNumber)
     {
         boolean removed = false;
         List allPages = getDocumentCatalog().getAllPages();
-        if( allPages.size() > pageNumber)
+        if (allPages.size() > pageNumber)
         {
-            PDPage page = (PDPage)allPages.get( pageNumber );
-            removed = removePage( page );
+            PDPage page = (PDPage) allPages.get(pageNumber);
+            removed = removePage(page);
         }
         return removed;
     }
 
     /**
-     * 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.
-     *
+     * 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.
+     * 
      * @param page The page to import.
      * @return The page that was imported.
-     *
+     * 
      * @throws IOException If there is an error copying the page.
      */
-    public PDPage importPage( PDPage page ) throws IOException
+    public PDPage importPage(PDPage page) throws IOException
     {
-        PDPage importedPage = new PDPage( new COSDictionary( page.getCOSDictionary() ) );
+        PDPage importedPage = new PDPage(new COSDictionary(page.getCOSDictionary()));
         InputStream is = null;
         OutputStream os = null;
         try
         {
             PDStream src = page.getContents();
-            if(src != null)
+            if (src != null)
             {
-                PDStream dest = new PDStream( document.createCOSStream());
-                importedPage.setContents( dest );
+                PDStream dest = new PDStream(document.createCOSStream());
+                importedPage.setContents(dest);
                 os = dest.createOutputStream();
 
                 byte[] buf = new byte[10240];
                 int amountRead = 0;
                 is = src.createInputStream();
-                while((amountRead = is.read(buf,0,10240)) > -1)
+                while ((amountRead = is.read(buf, 0, 10240)) > -1)
                 {
                     os.write(buf, 0, amountRead);
                 }
             }
-            addPage( importedPage );
+            addPage(importedPage);
         }
         finally
         {
-            if( is != null )
+            if (is != null)
             {
                 is.close();
             }
-            if( os != null )
+            if (os != null)
             {
                 os.close();
             }
@@ -683,19 +665,18 @@ public class PDDocument implements Pagea
     }
 
     /**
-     * Constructor that uses an existing document.  The COSDocument that
-     * is passed in must be valid.
-     *
+     * Constructor that uses an existing document. The COSDocument that is passed in must be valid.
+     * 
      * @param doc The COSDocument that this document wraps.
      */
-    public PDDocument( COSDocument doc )
+    public PDDocument(COSDocument doc)
     {
         document = doc;
     }
 
     /**
      * This will get the low level document.
-     *
+     * 
      * @return The document that this layer sits on top of.
      */
     public COSDocument getDocument()
@@ -704,53 +685,53 @@ public class PDDocument implements Pagea
     }
 
     /**
-     * This will get the document info dictionary.  This is guaranteed to not return null.
-     *
+     * This will get the document info dictionary. This is guaranteed to not return null.
+     * 
      * @return The documents /Info dictionary
      */
     public PDDocumentInformation getDocumentInformation()
     {
-        if( documentInformation == null )
+        if (documentInformation == null)
         {
             COSDictionary trailer = document.getTrailer();
-            COSDictionary infoDic = (COSDictionary)trailer.getDictionaryObject( COSName.INFO );
-            if( infoDic == null )
+            COSDictionary infoDic = (COSDictionary) trailer.getDictionaryObject(COSName.INFO);
+            if (infoDic == null)
             {
                 infoDic = new COSDictionary();
-                trailer.setItem( COSName.INFO, infoDic );
+                trailer.setItem(COSName.INFO, infoDic);
             }
-            documentInformation = new PDDocumentInformation( infoDic );
+            documentInformation = new PDDocumentInformation(infoDic);
         }
         return documentInformation;
     }
 
     /**
      * This will set the document information for this document.
-     *
+     * 
      * @param info The updated document information.
      */
-    public void setDocumentInformation( PDDocumentInformation info )
+    public void setDocumentInformation(PDDocumentInformation info)
     {
         documentInformation = info;
-        document.getTrailer().setItem( COSName.INFO, info.getDictionary() );
+        document.getTrailer().setItem(COSName.INFO, info.getDictionary());
     }
 
     /**
-     * This will get the document CATALOG.  This is guaranteed to not return null.
-     *
+     * This will get the document CATALOG. This is guaranteed to not return null.
+     * 
      * @return The documents /Root dictionary
      */
     public PDDocumentCatalog getDocumentCatalog()
     {
-        if( documentCatalog == null )
+        if (documentCatalog == null)
         {
             COSDictionary trailer = document.getTrailer();
-            COSBase dictionary = trailer.getDictionaryObject( COSName.ROOT );
-            if (dictionary instanceof COSDictionary) 
+            COSBase dictionary = trailer.getDictionaryObject(COSName.ROOT);
+            if (dictionary instanceof COSDictionary)
             {
                 documentCatalog = new PDDocumentCatalog(this, (COSDictionary) dictionary);
-            } 
-            else 
+            }
+            else
             {
                 documentCatalog = new PDDocumentCatalog(this);
             }
@@ -760,7 +741,7 @@ public class PDDocument implements Pagea
 
     /**
      * This will tell if this document is encrypted or not.
-     *
+     * 
      * @return true If this document is encrypted.
      */
     public boolean isEncrypted()
@@ -769,21 +750,20 @@ public class PDDocument implements Pagea
     }
 
     /**
-     * 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.
-     *
+     * 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.
+     * 
      * @return The encryption dictionary(most likely a PDStandardEncryption object)
-     *
+     * 
      * @throws IOException If there is an error determining which security handler to use.
      */
     public PDEncryptionDictionary getEncryptionDictionary() throws IOException
     {
-        if( encParameters == null )
+        if (encParameters == null)
         {
-            if( isEncrypted() )
+            if (isEncrypted())
             {
                 encParameters = new PDEncryptionDictionary(document.getEncryptionDictionary());
             }
@@ -793,32 +773,19 @@ public class PDDocument implements Pagea
 
     /**
      * This will set the encryption dictionary for this document.
-     *
+     * 
      * @param encDictionary The encryption dictionary(most likely a PDStandardEncryption object)
-     *
+     * 
      * @throws IOException If there is an error determining which security handler to use.
      */
-    public void setEncryptionDictionary( PDEncryptionDictionary encDictionary ) throws IOException
+    public void setEncryptionDictionary(PDEncryptionDictionary encDictionary) throws IOException
     {
         encParameters = encDictionary;
     }
 
     /**
      * This will return the last signature.
-     *
-     * @return the last signature as <code>PDSignature</code>.
-     * @throws IOException if no document catalog can be found.
-     * @deprecated use {@link #getLastSignatureDictionary()} instead.
-     */
-    @Deprecated
-    public PDSignature getSignatureDictionary() throws IOException
-    {
-        return getLastSignatureDictionary();
-    }
-
-    /**
-     * This will return the last signature.
-     *
+     * 
      * @return the last signature as <code>PDSignature</code>.
      * @throws IOException if no document catalog can be found.
      */
@@ -832,10 +799,10 @@ public class PDDocument implements Pagea
         }
         return null;
     }
-    
+
     /**
      * Retrieve all signature fields from the document.
-     *
+     * 
      * @return a <code>List</code> of <code>PDSignatureField</code>s
      * @throws IOException if no document catalog can be found.
      */
@@ -846,7 +813,7 @@ public class PDDocument implements Pagea
         if (acroForm != null)
         {
             List<COSDictionary> signatureDictionary = document.getSignatureFields(false);
-            for ( COSDictionary dict : signatureDictionary )
+            for (COSDictionary dict : signatureDictionary)
             {
                 fields.add(new PDSignatureField(acroForm, dict));
             }
@@ -856,7 +823,7 @@ public class PDDocument implements Pagea
 
     /**
      * Retrieve all signature dictionaries from the document.
-     *
+     * 
      * @return a <code>List</code> of <code>PDSignature</code>s
      * @throws IOException if no document catalog can be found.
      */
@@ -864,63 +831,25 @@ public class PDDocument implements Pagea
     {
         List<COSDictionary> signatureDictionary = document.getSignatureDictionaries();
         List<PDSignature> signatures = new LinkedList<PDSignature>();
-        for ( COSDictionary dict : signatureDictionary )
+        for (COSDictionary dict : signatureDictionary)
         {
             signatures.add(new PDSignature(dict));
         }
         return signatures;
     }
-    
-    /**
-     * This will determine if this is the user password.  This only applies when
-     * the document is encrypted and uses standard encryption.
-     *
-     * @param password The plain text user password.
-     *
-     * @return 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.
-     *
-     * @deprecated
-     */
-    @Deprecated
-    public boolean isUserPassword( String password ) throws IOException, CryptographyException
-    {
-        return false;
-    }
 
     /**
-     * This will determine if this is the owner password.  This only applies when
-     * the document is encrypted and uses standard encryption.
-     *
-     * @param password The plain text owner password.
-     *
-     * @return 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.
-     *
-     * @deprecated
-     */
-    @Deprecated
-    public boolean isOwnerPassword( String password ) throws IOException, CryptographyException
-    {
-        return false;
-    }
-
-    /**
-     * 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.
-     *
+     * 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.
+     * 
      * @param 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.
-     *
+     * 
      */
-    public void decrypt( String password ) throws CryptographyException, IOException, InvalidPasswordException
+    public void decrypt(String password) throws CryptographyException, IOException, InvalidPasswordException
     {
         try
         {
@@ -928,62 +857,44 @@ public class PDDocument implements Pagea
             this.openProtection(m);
             document.dereferenceObjectStreams();
         }
-        catch(BadSecurityHandlerException e)
+        catch (BadSecurityHandlerException e)
         {
             throw new CryptographyException(e);
         }
     }
 
     /**
-     * This will tell if the document was decrypted with the master password.  This
-     * entry is invalid if the PDF was not decrypted.
-     *
-     * @return true if the pdf was decrypted with the master password.
-     *
-     * @deprecated use <code>getCurrentAccessPermission</code> instead
-     */
-    @Deprecated
-    public boolean wasDecryptedWithOwnerPassword()
-    {
-        return false;
-    }
-
-    /**
-     * This will <b>mark</b> 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.
-     *
+     * This will <b>mark</b> 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.
+     * 
      * @param ownerPassword The owner password to encrypt the document.
      * @param 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.
-     *
+     * 
      */
-    public void encrypt( String ownerPassword, String userPassword )
-        throws CryptographyException, IOException
+    public void encrypt(String ownerPassword, String userPassword) throws CryptographyException, IOException
     {
         try
         {
-            StandardProtectionPolicy policy =
-                new StandardProtectionPolicy(ownerPassword, userPassword, new AccessPermission());
+            StandardProtectionPolicy policy = new StandardProtectionPolicy(ownerPassword, userPassword,
+                    new AccessPermission());
             this.protect(policy);
         }
-        catch(BadSecurityHandlerException e)
+        catch (BadSecurityHandlerException e)
         {
             throw new CryptographyException(e);
         }
     }
 
-
     /**
-     * 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 that was passed into the encrypt method. You should never use this method. This will not
+     * longer be valid once encryption has occured.
+     * 
      * @return The owner password passed to the encrypt method.
-     *
+     * 
      * @deprecated Do not rely on this method anymore.
      */
     @Deprecated
@@ -993,12 +904,11 @@ public class PDDocument implements Pagea
     }
 
     /**
-     * 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 that was passed into the encrypt method. You should never use this method. This will not longer
+     * be valid once encryption has occured.
+     * 
      * @return The user password passed to the encrypt method.
-     *
+     * 
      * @deprecated Do not rely on this method anymore.
      */
     @Deprecated
@@ -1008,55 +918,28 @@ public class PDDocument implements Pagea
     }
 
     /**
-     * Internal method do determine if the document will be encrypted when it is saved.
-     *
-     * @return True if encrypt has been called and the document
-     *              has not been saved yet.
-     *
-     * @deprecated Do not rely on this method anymore. It is the responsibility of
-     * COSWriter to hold this state
-     */
-    @Deprecated
-    public boolean willEncryptWhenSaving()
-    {
-        return false;
-    }
-
-    /**
-     * This shoule only be called by the COSWriter after encryption has completed.
-     *
-     * @deprecated Do not rely on this method anymore. It is the responsability of
-     * COSWriter to hold this state.
-     */
-    @Deprecated
-    public void clearWillEncryptWhenSaving()
-    {
-        //method is deprecated.
-    }
-
-    /**
      * This will load a document from a url.
-     *
+     * 
      * @param url The url to load the PDF from.
-     *
+     * 
      * @return The document that was loaded.
-     *
+     * 
      * @throws IOException If there is an error reading from the stream.
      */
-    public static PDDocument load( URL url ) throws IOException
+    public static PDDocument load(URL url) throws IOException
     {
-        return load( url.openStream() );
+        return load(url.openStream());
     }
+
     /**
-     * This will load a document from a url. Used for skipping corrupt
-     * pdf objects
-     *
+     * This will load a document from a url. Used for skipping corrupt pdf objects
+     * 
      * @param url The url to load the PDF from.
-     * @param force When true, the parser will skip corrupt pdf objects and 
-     * will continue parsing at the next object in the file
-     *
+     * @param force When true, the parser will skip corrupt pdf objects and will continue parsing at the next object in
+     *            the file
+     * 
      * @return The document that was loaded.
-     *
+     * 
      * @throws IOException If there is an error reading from the stream.
      */
     public static PDDocument load(URL url, boolean force) throws IOException
@@ -1066,321 +949,319 @@ public class PDDocument implements Pagea
 
     /**
      * This will load a document from a url.
-     *
+     * 
      * @param url The url to load the PDF from.
      * @param scratchFile A location to store temp PDFBox data for this document.
-     *
+     * 
      * @return The document that was loaded.
-     *
+     * 
      * @throws IOException If there is an error reading from the stream.
      */
-    public static PDDocument load( URL url, RandomAccess scratchFile ) throws IOException
+    public static PDDocument load(URL url, RandomAccess scratchFile) throws IOException
     {
-        return load( url.openStream(), scratchFile );
+        return load(url.openStream(), scratchFile);
     }
 
     /**
      * This will load a document from a file.
-     *
+     * 
      * @param filename The name of the file to load.
-     *
+     * 
      * @return The document that was loaded.
-     *
+     * 
      * @throws IOException If there is an error reading from the stream.
      */
-    public static PDDocument load( String filename ) throws IOException
+    public static PDDocument load(String filename) throws IOException
     {
-        return load( new FileInputStream( filename ) );
+        return load(new FileInputStream(filename));
     }
-    
+
     /**
-     * This will load a document from a file. Allows for skipping corrupt pdf
-     * objects
-     *
+     * This will load a document from a file. Allows for skipping corrupt pdf objects
+     * 
      * @param filename The name of the file to load.
-     * @param force When true, the parser will skip corrupt pdf objects and 
-     * will continue parsing at the next object in the file
-     *
+     * @param force When true, the parser will skip corrupt pdf objects and will continue parsing at the next object in
+     *            the file
+     * 
      * @return The document that was loaded.
-     *
+     * 
      * @throws IOException If there is an error reading from the stream.
      */
     public static PDDocument load(String filename, boolean force) throws IOException
     {
-        return load(new FileInputStream( filename ), force);
+        return load(new FileInputStream(filename), force);
     }
 
     /**
      * This will load a document from a file.
-     *
+     * 
      * @param filename The name of the file to load.
      * @param scratchFile A location to store temp PDFBox data for this document.
-     *
+     * 
      * @return The document that was loaded.
-     *
+     * 
      * @throws IOException If there is an error reading from the stream.
      */
-    public static PDDocument load( String filename, RandomAccess scratchFile ) throws IOException
+    public static PDDocument load(String filename, RandomAccess scratchFile) throws IOException
     {
-        return load( new FileInputStream( filename ), scratchFile );
+        return load(new FileInputStream(filename), scratchFile);
     }
 
     /**
      * This will load a document from a file.
-     *
+     * 
      * @param file The name of the file to load.
-     *
+     * 
      * @return The document that was loaded.
-     *
+     * 
      * @throws IOException If there is an error reading from the stream.
      */
-    public static PDDocument load( File file ) throws IOException
+    public static PDDocument load(File file) throws IOException
     {
-        return load( new FileInputStream( file ) );
+        return load(new FileInputStream(file));
     }
 
     /**
      * This will load a document from a file.
-     *
+     * 
      * @param file The name of the file to load.
      * @param scratchFile A location to store temp PDFBox data for this document.
-     *
+     * 
      * @return The document that was loaded.
-     *
+     * 
      * @throws IOException If there is an error reading from the stream.
      */
-    public static PDDocument load( File file, RandomAccess scratchFile ) throws IOException
+    public static PDDocument load(File file, RandomAccess scratchFile) throws IOException
     {
-        return load( new FileInputStream( file ), scratchFile );
+        return load(new FileInputStream(file), scratchFile);
     }
 
     /**
      * This will load a document from an input stream.
-     *
+     * 
      * @param input The stream that contains the document.
-     *
+     * 
      * @return The document that was loaded.
-     *
+     * 
      * @throws IOException If there is an error reading from the stream.
      */
-    public static PDDocument load( InputStream input ) throws IOException
+    public static PDDocument load(InputStream input) throws IOException
     {
-        return load( input, null );
+        return load(input, null);
     }
 
     /**
-     * This will load a document from an input stream.
-     * Allows for skipping corrupt pdf objects
-     *
+     * This will load a document from an input stream. Allows for skipping corrupt pdf objects
+     * 
      * @param input The stream that contains the document.
-     * @param force When true, the parser will skip corrupt pdf objects and 
-     * will continue parsing at the next object in the file
-     *
+     * @param force When true, the parser will skip corrupt pdf objects and will continue parsing at the next object in
+     *            the file
+     * 
      * @return The document that was loaded.
-     *
+     * 
      * @throws IOException If there is an error reading from the stream.
      */
     public static PDDocument load(InputStream input, boolean force) throws IOException
     {
         return load(input, null, force);
     }
-    
+
     /**
      * This will load a document from an input stream.
-     *
+     * 
      * @param input The stream that contains the document.
      * @param scratchFile A location to store temp PDFBox data for this document.
-     *
+     * 
      * @return The document that was loaded.
-     *
+     * 
      * @throws IOException If there is an error reading from the stream.
      */
-    public static PDDocument load( InputStream input, RandomAccess scratchFile ) throws IOException
+    public static PDDocument load(InputStream input, RandomAccess scratchFile) throws IOException
     {
-        PDFParser parser = new PDFParser( new BufferedInputStream( input ) , scratchFile );
+        PDFParser parser = new PDFParser(new BufferedInputStream(input), scratchFile);
         parser.parse();
         return parser.getPDDocument();
     }
-    
+
     /**
      * This will load a document from an input stream. Allows for skipping corrupt pdf objects
      * 
      * @param input The stream that contains the document.
      * @param scratchFile A location to store temp PDFBox data for this document.
-     * @param force When true, the parser will skip corrupt pdf objects and 
-     * will continue parsing at the next object in the file
-     *
+     * @param force When true, the parser will skip corrupt pdf objects and will continue parsing at the next object in
+     *            the file
+     * 
      * @return The document that was loaded.
-     *
+     * 
      * @throws IOException If there is an error reading from the stream.
      */
     public static PDDocument load(InputStream input, RandomAccess scratchFile, boolean force) throws IOException
     {
-        PDFParser parser = new PDFParser( new BufferedInputStream( input ), scratchFile, force);
+        PDFParser parser = new PDFParser(new BufferedInputStream(input), scratchFile, force);
         parser.parse();
         return parser.getPDDocument();
     }
 
-
     /**
      * Parses PDF with non sequential parser.
-     *  
-     * @param file  file to be loaded
-     * @param scratchFile  location to store temp PDFBox data for this document
-     *
+     * 
+     * @param file file to be loaded
+     * @param scratchFile location to store temp PDFBox data for this document
+     * 
      * @return loaded document
-     *
-     * @throws IOException  in case of a file reading or parsing error
+     * 
+     * @throws IOException in case of a file reading or parsing error
      */
-    public static PDDocument loadNonSeq( File file, RandomAccess scratchFile ) throws IOException
+    public static PDDocument loadNonSeq(File file, RandomAccess scratchFile) throws IOException
     {
-        return loadNonSeq( file, scratchFile, "" );
+        return loadNonSeq(file, scratchFile, "");
     }
-    
+
     /**
      * Parses PDF with non sequential parser.
-     *  
-     * @param file  file to be loaded
-     * @param scratchFile  location to store temp PDFBox data for this document
+     * 
+     * @param file file to be loaded
+     * @param scratchFile location to store temp PDFBox data for this document
      * @param password password to be used for decryption
-     *
+     * 
      * @return loaded document
-     *
-     * @throws IOException  in case of a file reading or parsing error
+     * 
+     * @throws IOException in case of a file reading or parsing error
      */
-    public static PDDocument loadNonSeq( File file, RandomAccess scratchFile, String password ) throws IOException
+    public static PDDocument loadNonSeq(File file, RandomAccess scratchFile, String password) throws IOException
     {
-        NonSequentialPDFParser parser = new NonSequentialPDFParser( file, scratchFile, password );
+        NonSequentialPDFParser parser = new NonSequentialPDFParser(file, scratchFile, password);
         parser.parse();
         return parser.getPDDocument();
     }
 
     /**
      * Parses PDF with non sequential parser.
-     *  
+     * 
      * @param input stream that contains the document.
      * @param scratchFile location to store temp PDFBox data for this document
-     *
+     * 
      * @return loaded document
-     *
-     * @throws IOException  in case of a file reading or parsing error
+     * 
+     * @throws IOException in case of a file reading or parsing error
      */
-    public static PDDocument loadNonSeq( InputStream input, RandomAccess scratchFile) throws IOException
+    public static PDDocument loadNonSeq(InputStream input, RandomAccess scratchFile) throws IOException
     {
         return loadNonSeq(input, scratchFile, "");
     }
 
     /**
      * Parses PDF with non sequential parser.
-     *  
+     * 
      * @param input stream that contains the document.
      * @param scratchFile location to store temp PDFBox data for this document
      * @param password password to be used for decryption
-     *
+     * 
      * @return loaded document
-     *
-     * @throws IOException  in case of a file reading or parsing error
+     * 
+     * @throws IOException in case of a file reading or parsing error
      */
-    public static PDDocument loadNonSeq( InputStream input, RandomAccess scratchFile, String password ) throws IOException
+    public static PDDocument loadNonSeq(InputStream input, RandomAccess scratchFile, String password)
+            throws IOException
     {
-        NonSequentialPDFParser parser = new NonSequentialPDFParser( input, scratchFile, password );
+        NonSequentialPDFParser parser = new NonSequentialPDFParser(input, scratchFile, password);
         parser.parse();
         return parser.getPDDocument();
     }
 
     /**
      * Save the document to a file.
-     *
+     * 
      * @param 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.
      */
-    public void save( String fileName ) throws IOException, COSVisitorException
+    public void save(String fileName) throws IOException, COSVisitorException
     {
-        save( new File( fileName ) );
+        save(new File(fileName));
     }
 
     /**
      * Save the document to a file.
-     *
+     * 
      * @param file 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.
      */
-    public void save( File file ) throws IOException, COSVisitorException
+    public void save(File file) throws IOException, COSVisitorException
     {
-        save( new FileOutputStream( file ) );
+        save(new FileOutputStream(file));
     }
 
     /**
      * This will save the document to an output stream.
-     *
+     * 
      * @param 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.
      */
-    public void save( OutputStream output ) throws IOException, COSVisitorException
+    public void save(OutputStream output) throws IOException, COSVisitorException
     {
-        //update the count in case any pages have been added behind the scenes.
+        // update the count in case any pages have been added behind the scenes.
         getDocumentCatalog().getPages().updateCount();
         COSWriter writer = null;
         try
         {
-            writer = new COSWriter( output );
-            writer.write( this );
+            writer = new COSWriter(output);
+            writer.write(this);
             writer.close();
         }
         finally
         {
-            if( writer != null )
+            if (writer != null)
             {
                 writer.close();
             }
         }
     }
 
-    /** 
+    /**
      * Save the pdf as incremental.
      * 
      * @param fileName the filename to be used
      * @throws IOException if something went wrong
-     * @throws COSVisitorException  if something went wrong
+     * @throws COSVisitorException if something went wrong
      */
-    public void saveIncremental( String fileName ) throws IOException, COSVisitorException
+    public void saveIncremental(String fileName) throws IOException, COSVisitorException
     {
-        saveIncremental( new FileInputStream( fileName ) , new FileOutputStream( fileName , true) );
+        saveIncremental(new FileInputStream(fileName), new FileOutputStream(fileName, true));
     }
-    
-    /** 
+
+    /**
      * Save the pdf as incremental.
      * 
-     * @param input 
+     * @param input
      * @param output
      * @throws IOException if something went wrong
-     * @throws COSVisitorException  if something went wrong
+     * @throws COSVisitorException if something went wrong
      */
-    public void saveIncremental( FileInputStream input, OutputStream output ) throws IOException, COSVisitorException
+    public void saveIncremental(FileInputStream input, OutputStream output) throws IOException, COSVisitorException
     {
-        //update the count in case any pages have been added behind the scenes.
+        // update the count in case any pages have been added behind the scenes.
         getDocumentCatalog().getPages().updateCount();
         COSWriter writer = null;
         try
         {
             // Sometimes the original file will be missing a newline at the end
             // In order to avoid having %%EOF the first object on the same line
-            // as the %%EOF, we put a newline here.  If there's already one at
+            // as the %%EOF, we put a newline here. If there's already one at
             // the end of the file, an extra one won't hurt. PDFBOX-1051
             output.write("\r\n".getBytes());
-            writer = new COSWriter( output, input );
-            writer.write( this );
+            writer = new COSWriter(output, input);
+            writer.write(this);
             writer.close();
         }
         finally
         {
-            if( writer != null )
+            if (writer != null)
             {
                 writer.close();
             }
@@ -1388,135 +1269,19 @@ public class PDDocument implements Pagea
     }
 
     /**
-     * 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!!
-     *
+     * This will return the total page count of the PDF document.
+     * 
      * @return The total number of pages in the PDF document.
-     * @deprecated Use the getNumberOfPages method instead!
-     */
-    @Deprecated
-    public int getPageCount()
-    {
-        return getNumberOfPages();
-    }
-
-    /**
-     * {@inheritDoc}
      */
     public int getNumberOfPages()
     {
         PDDocumentCatalog cat = getDocumentCatalog();
-        return (int)cat.getPages().getCount();
-    }
-
-    /**
-     * Returns the format of the page at the given index when using a
-     * default printer job returned by  {@link PrinterJob#getPrinterJob()}.
-     *
-     * @deprecated Use the {@link PDPageable} adapter class
-     * @param pageIndex page index, zero-based
-     * @return page format
-     */
-    @Deprecated
-    public PageFormat getPageFormat(int pageIndex)
-    {
-        try 
-        {
-            PrinterJob printerJob = PrinterJob.getPrinterJob();
-            return new PDPageable(this, printerJob).getPageFormat(pageIndex);
-        } 
-        catch (PrinterException e) 
-        {
-            throw new RuntimeException(e);
-        }
-    } 
-
-    /**
-     * {@inheritDoc}
-     */
-    public Printable getPrintable(int pageIndex)
-    {
-        return (Printable)getDocumentCatalog().getAllPages().get( pageIndex );
-    }
-
-    /**
-     * @see PDDocument#print()
-     *
-     * @param printJob The printer job.
-     *
-     * @throws 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 print(PrinterJob printJob) throws PrinterException
-    {
-        print(printJob, false);
-    }
-
-    /**
-     * 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.
-     *
-     * @throws 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 print() throws PrinterException
-    {
-        print( PrinterJob.getPrinterJob() );
-    }
-
-    /**
-     * This will send the PDF to the default printer without prompting the user
-     * for any printer settings.
-     *
-     * @see PDDocument#print()
-     *
-     * @throws PrinterException If there is an error while printing.
-     */
-    public void silentPrint() throws PrinterException
-    {
-        silentPrint( PrinterJob.getPrinterJob() );
-    }
-
-    /**
-     * This will send the PDF to the default printer without prompting the user
-     * for any printer settings.
-     *
-     * @param printJob A printer job definition.
-     * @see PDDocument#print()
-     *
-     * @throws PrinterException If there is an error while printing.
-     */
-    public void silentPrint( PrinterJob printJob ) throws PrinterException
-    {
-        print(printJob, true);
-    }
-
-    private void print(PrinterJob job, boolean silent) throws PrinterException 
-    {
-        if (job == null) 
-        {
-            throw new PrinterException("The given printer job is null.");
-        } 
-        else 
-        {
-            job.setPageable(new PDPageable(this, job));
-            if (silent || job.printDialog()) 
-            {
-                job.print();
-            }
-        }
+        return (int) cat.getPages().getCount();
     }
 
     /**
      * This will close the underlying COSDocument object.
-     *
+     * 
      * @throws IOException If there is an error releasing resources.
      */
     public void close() throws IOException
@@ -1524,16 +1289,15 @@ public class PDDocument implements Pagea
         document.close();
     }
 
-
     /**
-     * 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.
-     *
+     * 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.
+     * 
      * @see org.apache.pdfbox.pdmodel.encryption.StandardProtectionPolicy
      * @see org.apache.pdfbox.pdmodel.encryption.PublicKeyProtectionPolicy
-     *
+     * 
      * @param pp The protection policy.
-     *
+     * 
      * @throws BadSecurityHandlerException If there is an error during protection.
      */
     public void protect(ProtectionPolicy pp) throws BadSecurityHandlerException
@@ -1544,26 +1308,26 @@ public class PDDocument implements Pagea
 
     /**
      * Tries to decrypt the document in memory using the provided decryption material.
-     *
-     *  @see org.apache.pdfbox.pdmodel.encryption.StandardDecryptionMaterial
-     *  @see org.apache.pdfbox.pdmodel.encryption.PublicKeyDecryptionMaterial
-     *
+     * 
+     * @see org.apache.pdfbox.pdmodel.encryption.StandardDecryptionMaterial
+     * @see org.apache.pdfbox.pdmodel.encryption.PublicKeyDecryptionMaterial
+     * 
      * @param pm The decryption material (password or certificate).
-     *
+     * 
      * @throws BadSecurityHandlerException If there is an error during decryption.
      * @throws IOException If there is an error reading cryptographic information.
      * @throws CryptographyException If there is an error during decryption.
      */
-    public void openProtection(DecryptionMaterial pm)
-        throws BadSecurityHandlerException, IOException, CryptographyException
+    public void openProtection(DecryptionMaterial pm) throws BadSecurityHandlerException, IOException,
+            CryptographyException
     {
         PDEncryptionDictionary dict = this.getEncryptionDictionary();
-        if(dict.getFilter() != null)
+        if (dict.getFilter() != null)
         {
             securityHandler = SecurityHandlersManager.getInstance().getSecurityHandler(dict.getFilter());
             securityHandler.decryptDocument(this, pm);
             document.dereferenceObjectStreams();
-            document.setEncryptionDictionary( null );
+            document.setEncryptionDictionary(null);
         }
         else
         {
@@ -1572,19 +1336,17 @@ public class PDDocument implements Pagea
     }
 
     /**
-     * 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.
-     *
+     * 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.
+     * 
      * @return the access permissions for the current user on the document.
      */
 
     public AccessPermission getCurrentAccessPermission()
     {
-        if(this.securityHandler == null)
+        if (this.securityHandler == null)
         {
             return AccessPermission.getOwnerAccessPermission();
         }
@@ -1593,24 +1355,24 @@ public class PDDocument implements Pagea
 
     /**
      * Get the security handler that is used for document encryption.
-     *
+     * 
      * @return The handler used to encrypt/decrypt the document.
      */
     public SecurityHandler getSecurityHandler()
     {
         return securityHandler;
     }
-    
+
     /**
      * Sets security handler if none is set already.
      * 
      * @param secHandler security handler to be assigned to document
-     * @return  <code>true</code> if security handler was set, <code>false</code>
-     *          otherwise (a security handler was already set)
+     * @return <code>true</code> if security handler was set, <code>false</code> otherwise (a security handler was
+     *         already set)
      */
     public boolean setSecurityHandler(SecurityHandler secHandler)
     {
-        if ( securityHandler == null )
+        if (securityHandler == null)
         {
             securityHandler = secHandler;
             return true;
@@ -1620,6 +1382,7 @@ public class PDDocument implements Pagea
 
     /**
      * Indicates if all security is removed or not when writing the pdf.
+     * 
      * @return returns true if all security shall be removed otherwise false
      */
     public boolean isAllSecurityToBeRemoved()
@@ -1629,22 +1392,21 @@ public class PDDocument implements Pagea
 
     /**
      * Activates/Deactivates the removal of all security when writing the pdf.
-     *  
+     * 
      * @param removeAllSecurity remove all security if set to true
      */
     public void setAllSecurityToBeRemoved(boolean removeAllSecurity)
     {
         allSecurityToBeRemoved = removeAllSecurity;
     }
-    
-    public Long getDocumentId() 
+
+    public Long getDocumentId()
     {
-      return documentId;
+        return documentId;
     }
-    
+
     public void setDocumentId(Long docId)
     {
-      documentId = docId;
+        documentId = docId;
     }
 }
-



Mime
View raw message