You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2012/05/15 23:34:08 UTC

svn commit: r1338903 - in /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox: pdfparser/NonSequentialPDFParser.java pdmodel/PDDocument.java

Author: lehmi
Date: Tue May 15 21:34:07 2012
New Revision: 1338903

URL: http://svn.apache.org/viewvc?rev=1338903&view=rev
Log:
PDFBOX-1311: added a constructor/method to handle a password to be used for decryption

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java?rev=1338903&r1=1338902&r2=1338903&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/NonSequentialPDFParser.java Tue May 15 21:34:07 2012
@@ -134,8 +134,38 @@ public class NonSequentialPDFParser exte
      *  
      * @throws IOException If something went wrong.
      */
+    /** 
+     * Constructs parser for given file using given buffer for temporary storage. 
+     * 
+     * @param file the pdf to be parsed
+     * @param raBuf the buffer to be used for parsing
+     *  
+     * @throws IOException If something went wrong.
+     */
     public NonSequentialPDFParser( File file, RandomAccess raBuf ) throws IOException
     {
+        this(file, raBuf, "");
+    }
+    
+    /** 
+     * Constructs parser for given file using given buffer for temporary storage. 
+     * 
+     * @param file the pdf to be parsed
+     * @param raBuf the buffer to be used for parsing
+     *  
+     * @throws IOException If something went wrong.
+     */
+    /** 
+     * Constructs parser for given file using given buffer for temporary storage. 
+     * 
+     * @param file the pdf to be parsed
+     * @param raBuf the buffer to be used for parsing
+     * @param decryptionPassword password to be used for decryption
+     *  
+     * @throws IOException If something went wrong.
+     */
+    public NonSequentialPDFParser( File file, RandomAccess raBuf, String decryptionPassword ) throws IOException
+    {
         super( EMPTY_INPUT_STREAM, null, false );
             
         String eofLookupRangeStr = System.getProperty( SYSPROP_EOFLOOKUPRANGE );
@@ -159,6 +189,8 @@ public class NonSequentialPDFParser exte
                                          new COSDocument( raBuf, false ) );
     
         pdfSource = new PushBackInputStream( raStream, 4096 );
+        
+        password = decryptionPassword;
     }
         
     // ------------------------------------------------------------------------

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=1338903&r1=1338902&r2=1338903&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 Tue May 15 21:34:07 2012
@@ -1104,11 +1104,27 @@ public class PDDocument implements Pagea
      */
     public static PDDocument loadNonSeq( File file, RandomAccess scratchFile ) throws IOException
     {
-    	  NonSequentialPDFParser parser = new NonSequentialPDFParser( 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 password password to be used for decryption
+     *
+     * @return loaded document
+     *
+     * @throws IOException  in case of a file reading or parsing error
+     */
+    public static PDDocument loadNonSeq( File file, RandomAccess scratchFile, String password ) throws IOException
+    {
+        NonSequentialPDFParser parser = new NonSequentialPDFParser( file, scratchFile, password );
         parser.parse();
         return parser.getPDDocument();
     }
-    
+
     /**
      * This will save this document to the filesystem.
      *