Author: tilman
Date: Fri Jun  6 14:08:36 2025
New Revision: 1926180

URL: http://svn.apache.org/viewvc?rev=1926180&view=rev
Log:
PDFBOX-6016: pass source to PDDocument so that it can be closed

Modified:
    
pdfbox/branches/3.0/preflight/src/main/java/org/apache/pdfbox/preflight/PreflightDocument.java
    
pdfbox/branches/3.0/preflight/src/main/java/org/apache/pdfbox/preflight/parser/PreflightParser.java

Modified: 
pdfbox/branches/3.0/preflight/src/main/java/org/apache/pdfbox/preflight/PreflightDocument.java
URL: 
http://svn.apache.org/viewvc/pdfbox/branches/3.0/preflight/src/main/java/org/apache/pdfbox/preflight/PreflightDocument.java?rev=1926180&r1=1926179&r2=1926180&view=diff
==============================================================================
--- 
pdfbox/branches/3.0/preflight/src/main/java/org/apache/pdfbox/preflight/PreflightDocument.java
 (original)
+++ 
pdfbox/branches/3.0/preflight/src/main/java/org/apache/pdfbox/preflight/PreflightDocument.java
 Fri Jun  6 14:08:36 2025
@@ -26,6 +26,7 @@ import java.util.Collections;
 import java.util.List;
 
 import org.apache.pdfbox.cos.COSDocument;
+import org.apache.pdfbox.io.RandomAccessRead;
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.pdfbox.preflight.ValidationResult.ValidationError;
 import org.apache.pdfbox.preflight.exception.ValidationException;
@@ -49,20 +50,37 @@ public class PreflightDocument extends P
      */
     public PreflightDocument(COSDocument doc, Format format)
     {
-        this(doc, format, null);
+        this(doc, format, null, null);
     }
 
     /**
      * Create a preflight document based on the COSDocument that will use the 
given configuration bean to process the
-     * validation. if the configuration is null, a default configuration will 
be load using the given format.
+     * validation. If the configuration is null, a default configuration will 
be loaded using the given format.
      * 
      * @param doc the underlying COSDocument
      * @param format the format used for validation
      * @param config the configuration used for validation
+     *
+     * @deprecated use the 4 parameter constructor and pass the source.
      */
+    @Deprecated
     public PreflightDocument(COSDocument doc, Format format, 
PreflightConfiguration config)
     {
-        super(doc);
+        this(doc, format, config, null);
+    }
+
+    /**
+     * Create a preflight document based on the COSDocument that will use the 
given configuration bean to process the
+     * validation. If the configuration is null, a default configuration will 
be loaded using the given format.
+     * 
+     * @param doc the underlying COSDocument
+     * @param format the format used for validation
+     * @param config the configuration used for validation
+     * @param source input representing the pdf
+     */
+    public PreflightDocument(COSDocument doc, Format format, 
PreflightConfiguration config, RandomAccessRead source)
+    {
+        super(doc, source);
         this.specification = format;
         // PDF/A1-b is default
         this.config = config == null ? 
PreflightConfiguration.createPdfA1BConfiguration() : config;

Modified: 
pdfbox/branches/3.0/preflight/src/main/java/org/apache/pdfbox/preflight/parser/PreflightParser.java
URL: 
http://svn.apache.org/viewvc/pdfbox/branches/3.0/preflight/src/main/java/org/apache/pdfbox/preflight/parser/PreflightParser.java?rev=1926180&r1=1926179&r2=1926180&view=diff
==============================================================================
--- 
pdfbox/branches/3.0/preflight/src/main/java/org/apache/pdfbox/preflight/parser/PreflightParser.java
 (original)
+++ 
pdfbox/branches/3.0/preflight/src/main/java/org/apache/pdfbox/preflight/parser/PreflightParser.java
 Fri Jun  6 14:08:36 2025
@@ -146,6 +146,7 @@ public class PreflightParser extends PDF
      * 
      * @param format
      *            format that the document should follow (default {@link 
Format#PDF_A1B})
+     * @return the parsed document.
      * @throws IOException
      */
     public PDDocument parse(Format format) throws IOException
@@ -161,6 +162,7 @@ public class PreflightParser extends PDF
      * @param config
      *            Configuration bean that will be used by the 
PreflightDocument. If null the format is used to determine
      *            the default configuration.
+     * @return the parsed document.
      * @throws IOException
      */
     public PDDocument parse(Format format, PreflightConfiguration config) 
throws IOException
@@ -193,7 +195,7 @@ public class PreflightParser extends PDF
     @Override
     protected PDDocument createDocument() throws IOException
     {
-        preflightDocument = new PreflightDocument(document, format, config);
+        preflightDocument = new PreflightDocument(document, format, config, 
source);
         return preflightDocument;
     }
 


Reply via email to