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 2016/03/12 15:30:28 UTC

svn commit: r1734708 - in /pdfbox/trunk: pdfbox/src/main/java/org/apache/pdfbox/multipdf/Overlay.java tools/src/main/java/org/apache/pdfbox/tools/OverlayPDF.java

Author: lehmi
Date: Sat Mar 12 14:30:28 2016
New Revision: 1734708

URL: http://svn.apache.org/viewvc?rev=1734708&view=rev
Log:
PDFBOX-3263: close input files after saving the resulting pdf as some streams are shared among the input and output files

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/Overlay.java
    pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/OverlayPDF.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/Overlay.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/Overlay.java?rev=1734708&r1=1734707&r2=1734708&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/Overlay.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/Overlay.java Sat Mar 12 14:30:28 2016
@@ -102,45 +102,50 @@ public class Overlay
     public PDDocument overlay(Map<Integer, String> specificPageOverlayFile)
             throws IOException
     {
-        try
+        loadPDFs();
+        for (Map.Entry<Integer, String> e : specificPageOverlayFile.entrySet())
         {
-            loadPDFs();
-            for (Map.Entry<Integer, String> e : specificPageOverlayFile.entrySet())
-            {
-                PDDocument doc = loadPDF(e.getValue());
-                specificPageOverlay.put(e.getKey(), doc);
-                specificPageOverlayPage.put(e.getKey(), getLayoutPage(doc));
-            }
-            processPages(inputPDFDocument);
+            PDDocument doc = loadPDF(e.getValue());
+            specificPageOverlay.put(e.getKey(), doc);
+            specificPageOverlayPage.put(e.getKey(), getLayoutPage(doc));
+        }
+        processPages(inputPDFDocument);
+        return inputPDFDocument;
+    }
 
-            return inputPDFDocument;
+    /**
+     * Close all input pdfs which were used for the overlay.
+     * 
+     * @throws IOException if something went wrong
+     */
+    public void close() throws IOException
+    {
+        if (defaultOverlay != null)
+        {
+            defaultOverlay.close();
         }
-        finally
+        if (firstPageOverlay != null)
+        {
+            firstPageOverlay.close();
+        }
+        if (lastPageOverlay != null)
+        {
+            lastPageOverlay.close();
+        }
+        if (allPagesOverlay != null)
+        {
+            allPagesOverlay.close();
+        }
+        if (oddPageOverlay != null)
+        {
+            oddPageOverlay.close();
+        }
+        if (evenPageOverlay != null)
+        {
+            evenPageOverlay.close();
+        }
+        if (specificPageOverlay != null)
         {
-            if (defaultOverlay != null)
-            {
-                defaultOverlay.close();
-            }
-            if (firstPageOverlay != null)
-            {
-                firstPageOverlay.close();
-            }
-            if (lastPageOverlay != null)
-            {
-                lastPageOverlay.close();
-            }
-            if (allPagesOverlay != null)
-            {
-                allPagesOverlay.close();
-            }
-            if (oddPageOverlay != null)
-            {
-                oddPageOverlay.close();
-            }
-            if (evenPageOverlay != null)
-            {
-                evenPageOverlay.close();
-            }
             for (Map.Entry<Integer, PDDocument> e : specificPageOverlay.entrySet())
             {
                 e.getValue().close();

Modified: pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/OverlayPDF.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/OverlayPDF.java?rev=1734708&r1=1734707&r2=1734708&view=diff
==============================================================================
--- pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/OverlayPDF.java (original)
+++ pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/OverlayPDF.java Sat Mar 12 14:30:28 2016
@@ -142,6 +142,9 @@ public final class OverlayPDF
             PDDocument result = overlayer.overlay(specificPageOverlayFile);
             result.save(outputFilename);
             result.close();
+            // close the input files AFTER saving the resulting file as some 
+            // streams are shared among the input and the output files
+            overlayer.close();
         } 
         catch (IOException e) 
         {