pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1617990 - /pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/PDFMergerUtility.java
Date Thu, 14 Aug 2014 16:28:31 GMT
Author: tilman
Date: Thu Aug 14 16:28:30 2014
New Revision: 1617990

URL: http://svn.apache.org/r1617990
Log:
PDFBOX-1511: don't share resources between different source files, as suggested by Kirk Haines

Modified:
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/PDFMergerUtility.java

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/PDFMergerUtility.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/PDFMergerUtility.java?rev=1617990&r1=1617989&r2=1617990&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/PDFMergerUtility.java
(original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/PDFMergerUtility.java
Thu Aug 14 16:28:30 2014
@@ -37,13 +37,13 @@ import org.apache.pdfbox.cos.COSNumber;
 import org.apache.pdfbox.cos.COSStream;
 import org.apache.pdfbox.cos.COSString;
 import org.apache.pdfbox.exceptions.COSVisitorException;
-import org.apache.pdfbox.filter.JPXFilter;
 import org.apache.pdfbox.io.RandomAccess;
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.pdfbox.pdmodel.PDDocumentCatalog;
 import org.apache.pdfbox.pdmodel.PDDocumentInformation;
 import org.apache.pdfbox.pdmodel.PDDocumentNameDictionary;
 import org.apache.pdfbox.pdmodel.PDPage;
+import org.apache.pdfbox.pdmodel.PDResources;
 import org.apache.pdfbox.pdmodel.common.COSArrayList;
 import org.apache.pdfbox.pdmodel.common.PDNumberTreeNode;
 import org.apache.pdfbox.pdmodel.common.PDStream;
@@ -223,16 +223,8 @@ public class PDFMergerUtility
             try
             {
                 Iterator<InputStream> sit = sources.iterator();
-                sourceFile = sit.next();
-                if (isNonSeq)
-                {
-                    destination = PDDocument.loadNonSeq(sourceFile, scratchFile);
-                }
-                else
-                {
-                    destination = PDDocument.load(sourceFile);
-                }
-
+                destination = new PDDocument();
+                
                 while (sit.hasNext())
                 {
                     sourceFile = sit.next();
@@ -312,23 +304,6 @@ public class PDFMergerUtility
             destCatalog.setOpenAction(srcCatalog.getOpenAction());
         }
 
-        // maybe there are some shared resources for all pages
-        COSDictionary srcPages = (COSDictionary) srcCatalog.getCOSDictionary().getDictionaryObject(COSName.PAGES);
-        COSDictionary srcResources = (COSDictionary) srcPages.getDictionaryObject(COSName.RESOURCES);
-        COSDictionary destPages = (COSDictionary) destCatalog.getCOSDictionary().getDictionaryObject(COSName.PAGES);
-        COSDictionary destResources = (COSDictionary) destPages.getDictionaryObject(COSName.RESOURCES);
-        if (srcResources != null)
-        {
-            if (destResources != null)
-            {
-                destResources.mergeInto(srcResources);
-            }
-            else
-            {
-                destPages.setItem(COSName.RESOURCES, srcResources);
-            }
-        }
-
         PDFCloneUtility cloner = new PDFCloneUtility(destination);
 
         try
@@ -386,7 +361,6 @@ public class PDFMergerUtility
             {
                 cloner.cloneMerge(srcNames, destNames);
             }
-
         }
 
         PDDocumentOutline destOutline = destCatalog.getDocumentOutline();
@@ -512,7 +486,6 @@ public class PDFMergerUtility
             }
         }
 
-        // finally append the pages
         List<PDPage> pages = srcCatalog.getAllPages();
         Iterator<PDPage> pageIter = pages.iterator();
         HashMap<COSDictionary, COSDictionary> objMapping = new HashMap<COSDictionary,
COSDictionary>();
@@ -523,6 +496,8 @@ public class PDFMergerUtility
             newPage.setCropBox(page.findCropBox());
             newPage.setMediaBox(page.findMediaBox());
             newPage.setRotation(page.findRotation());
+            // this is smart enough to just create references for resources that are used
on multiple pages
+            newPage.setResources(new PDResources((COSDictionary) cloner.cloneForNewDocument(page.findResources())));
                       
             if (mergeStructTree)
             {
                 updateStructParentEntries(newPage, destParentTreeNextKey);



Mime
View raw message