pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1838441 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java
Date Mon, 20 Aug 2018 17:17:48 GMT
Author: lehmi
Date: Mon Aug 20 17:17:48 2018
New Revision: 1838441

URL: http://svn.apache.org/viewvc?rev=1838441&view=rev
Log:
PDFBOX-4295: readded try-catch

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java?rev=1838441&r1=1838440&r2=1838441&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java Mon
Aug 20 17:17:48 2018
@@ -330,35 +330,42 @@ public class PDFMergerUtility
             for (Object sourceObject : sources)
             {
                 PDDocument sourceDoc = null;
-                if (sourceObject instanceof File)
+                try
                 {
-                    sourceDoc = PDDocument.load((File) sourceObject, memUsageSetting);
-                }
-                else
-                {
-                    sourceDoc = PDDocument.load((InputStream) sourceObject, memUsageSetting);
-                }
-                for (PDPage page : sourceDoc.getPages())
-                {
-                    PDPage newPage = new PDPage(
-                            (COSDictionary) cloner.cloneForNewDocument(page.getCOSObject()));
-                    newPage.setCropBox(page.getCropBox());
-                    newPage.setMediaBox(page.getMediaBox());
-                    newPage.setRotation(page.getRotation());
-                    PDResources resources = page.getResources();
-                    if (resources != null)
+                    if (sourceObject instanceof File)
                     {
-                        // this is smart enough to just create references for resources that
are used on multiple pages
-                        newPage.setResources(new PDResources(
-                                (COSDictionary) cloner.cloneForNewDocument(resources)));
+                        sourceDoc = PDDocument.load((File) sourceObject, memUsageSetting);
                     }
                     else
                     {
-                        newPage.setResources(new PDResources());
+                        sourceDoc = PDDocument.load((InputStream) sourceObject, memUsageSetting);
                     }
-                    destination.addPage(newPage);
+                    for (PDPage page : sourceDoc.getPages())
+                    {
+                        PDPage newPage = new PDPage(
+                                (COSDictionary) cloner.cloneForNewDocument(page.getCOSObject()));
+                        newPage.setCropBox(page.getCropBox());
+                        newPage.setMediaBox(page.getMediaBox());
+                        newPage.setRotation(page.getRotation());
+                        PDResources resources = page.getResources();
+                        if (resources != null)
+                        {
+                            // this is smart enough to just create references for resources
that are used on multiple
+                            // pages
+                            newPage.setResources(new PDResources(
+                                    (COSDictionary) cloner.cloneForNewDocument(resources)));
+                        }
+                        else
+                        {
+                            newPage.setResources(new PDResources());
+                        }
+                        destination.addPage(newPage);
+                    }
+                }
+                finally
+                {
+                    IOUtils.closeQuietly(sourceDoc);
                 }
-                sourceDoc.close();
             }
             
             if (destinationStream == null)



Mime
View raw message