pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1868031 - in /pdfbox/branches/issue4569/pdfbox/src: main/java/org/apache/pdfbox/pdfparser/ main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/ test/java/org/apache/pdfbox/pdfparser/
Date Sat, 05 Oct 2019 16:36:09 GMT
Author: lehmi
Date: Sat Oct  5 16:36:09 2019
New Revision: 1868031

URL: http://svn.apache.org/viewvc?rev=1868031&view=rev
Log:
PDFBOX-4569: merge PDFParser#parse and PDFParser#getPDDocument

Modified:
    pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java
    pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFParser.java
    pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/SignatureOptions.java
    pdfbox/branches/issue4569/pdfbox/src/test/java/org/apache/pdfbox/pdfparser/TestPDFParser.java

Modified: pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java?rev=1868031&r1=1868030&r2=1868031&view=diff
==============================================================================
--- pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java
(original)
+++ pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java
Sat Oct  5 16:36:09 2019
@@ -58,13 +58,10 @@ import org.apache.pdfbox.pdmodel.encrypt
 import org.apache.pdfbox.pdmodel.encryption.StandardDecryptionMaterial;
 
 /**
- * PDF-Parser which first reads startxref and xref tables in order to know valid objects
and parse only these objects.
+ * COS-Parser which first reads startxref and xref tables in order to know valid objects
and parse only these objects.
  * 
- * First {@link PDFParser#parse()} or  {@link FDFParser#parse()} must be called before page
objects
- * can be retrieved, e.g. {@link PDFParser#getPDDocument()}.
- * 
- * This class is a much enhanced version of <code>QuickParser</code> presented
in <a
- * href="https://issues.apache.org/jira/browse/PDFBOX-1104">PDFBOX-1104</a> by Jeremy
Villalobos.
+ * This class is a much enhanced version of <code>QuickParser</code> presented
in
+ * <a href="https://issues.apache.org/jira/browse/PDFBOX-1104">PDFBOX-1104</a>
by Jeremy Villalobos.
  */
 public class COSParser extends BaseParser implements ICOSParser
 {
@@ -567,7 +564,7 @@ public class COSParser extends BaseParse
      * @param lenient try to handle malformed PDFs.
      *
      */
-    public void setLenient(boolean lenient)
+    protected void setLenient(boolean lenient)
     {
         if (initialParseDone)
         {

Modified: pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFParser.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFParser.java?rev=1868031&r1=1868030&r2=1868031&view=diff
==============================================================================
--- pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFParser.java
(original)
+++ pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFParser.java
Sat Oct  5 16:36:09 2019
@@ -198,8 +198,7 @@ public class PDFParser extends COSParser
         ScratchFile scratchFile = new ScratchFile(memUsageSetting);
         RandomAccessRead source = new RandomAccessBuffer(input);
         PDFParser parser = new PDFParser(source, password, keyStore, alias, scratchFile);
-        parser.parse();
-        return parser.getPDDocument();
+        return parser.parse();
     }
 
     private void init(ScratchFile scratchFile) throws IOException
@@ -340,8 +339,7 @@ public class PDFParser extends COSParser
         try
         {
             PDFParser parser = new PDFParser(raFile, password, keyStore, alias, scratchFile);
-            parser.parse();
-            return parser.getPDDocument();
+            return parser.parse();
         }
         catch (IOException ioe)
         {
@@ -462,8 +460,7 @@ public class PDFParser extends COSParser
         {
             RandomAccessRead source = scratchFile.createBuffer(input);
             PDFParser parser = new PDFParser(source, password, keyStore, alias, scratchFile);
-            parser.parse();
-            return parser.getPDDocument();
+            return parser.parse();
         }
         catch (IOException ioe)
         {
@@ -473,21 +470,6 @@ public class PDFParser extends COSParser
     }
 
     /**
-     * This will get the PD document that was parsed. When you are done with this document
you must call close() on it
-     * to release resources.
-     *
-     * @return The document at the PD layer.
-     *
-     * @throws IOException If there is an error getting the document.
-     */
-    public PDDocument getPDDocument() throws IOException
-    {
-        PDDocument doc = new PDDocument(getDocument(), source, getAccessPermission());
-        doc.setEncryptionDictionary(getEncryption());
-        return doc;
-    }
-
-    /**
      * The initial parse will first parse only the trailer, the xrefstart and all xref tables
to have a pointer (offset)
      * to all the pdf's objects. It can handle linearized pdfs, which will have an xref at
the end pointing to an xref
      * at the beginning of the file. Last the root object is parsed.
@@ -516,19 +498,32 @@ public class PDFParser extends COSParser
     }
 
     /**
-     * This will parse the stream and populate the COSDocument object.  This will close
-     * the keystore stream when it is done parsing.
+     * This will parse the stream and populate the PDDocument object. This will close the
keystore stream when it is
+     * done parsing. Lenient mode is active by default.
+     *
+     * @throws InvalidPasswordException If the password is incorrect.
+     * @throws IOException If there is an error reading from the stream or corrupt data is
found.
+     */
+    public PDDocument parse() throws IOException
+    {
+        return parse(true);
+    }
+
+    /**
+     * This will parse the stream and populate the PDDocument object. This will close the
keystore stream when it is
+     * done parsing.
      *
+     * @param lenient activate leniency if set to true
      * @throws InvalidPasswordException If the password is incorrect.
-     * @throws IOException If there is an error reading from the stream or corrupt data
-     * is found.
+     * @throws IOException If there is an error reading from the stream or corrupt data is
found.
      */
-    public void parse() throws IOException
+    public PDDocument parse(boolean lenient) throws IOException
     {
-         // set to false if all is processed
-         boolean exceptionOccurred = true; 
-         try
-         {
+        setLenient(lenient);
+        // set to false if all is processed
+        boolean exceptionOccurred = true;
+        try
+        {
             // PDFBOX-1922 read the version header and rewind
             if (!parsePDFHeader() && !parseFDFHeader())
             {
@@ -540,6 +535,9 @@ public class PDFParser extends COSParser
                 initialParse();
             }
             exceptionOccurred = false;
+            PDDocument pdDocument = new PDDocument(getDocument(), source, getAccessPermission());
+            pdDocument.setEncryptionDictionary(getEncryption());
+            return pdDocument;
         }
         finally
         {

Modified: pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/SignatureOptions.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/SignatureOptions.java?rev=1868031&r1=1868030&r2=1868031&view=diff
==============================================================================
--- pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/SignatureOptions.java
(original)
+++ pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/SignatureOptions.java
Sat Oct  5 16:36:09 2019
@@ -97,8 +97,7 @@ public class SignatureOptions implements
     {
         pdfSource = rar;
         PDFParser parser = new PDFParser(pdfSource);
-        parser.parse();
-        visualSignature = parser.getDocument();
+        visualSignature = parser.parse().getDocument();
     }
 
     /**

Modified: pdfbox/branches/issue4569/pdfbox/src/test/java/org/apache/pdfbox/pdfparser/TestPDFParser.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/issue4569/pdfbox/src/test/java/org/apache/pdfbox/pdfparser/TestPDFParser.java?rev=1868031&r1=1868030&r2=1868031&view=diff
==============================================================================
--- pdfbox/branches/issue4569/pdfbox/src/test/java/org/apache/pdfbox/pdfparser/TestPDFParser.java
(original)
+++ pdfbox/branches/issue4569/pdfbox/src/test/java/org/apache/pdfbox/pdfparser/TestPDFParser.java
Sat Oct  5 16:36:09 2019
@@ -30,7 +30,6 @@ import java.io.FilenameFilter;
 import java.io.IOException;
 import java.net.URISyntaxException;
 
-import org.apache.pdfbox.cos.COSDocument;
 import org.apache.pdfbox.io.MemoryUsageSetting;
 import org.apache.pdfbox.io.RandomAccessBufferedFileInputStream;
 import org.apache.pdfbox.io.RandomAccessRead;
@@ -349,8 +348,7 @@ public class TestPDFParser
     {
         ScratchFile scratchFile = new ScratchFile(memUsageSetting);
         PDFParser pdfParser = new PDFParser(source, scratchFile);
-        pdfParser.parse();
-        try (COSDocument doc = pdfParser.getDocument())
+        try (PDDocument doc = pdfParser.parse())
         {
             assertNotNull(doc);
         }



Mime
View raw message