pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1849273 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java
Date Wed, 19 Dec 2018 07:49:05 GMT
Author: tilman
Date: Wed Dec 19 07:49:05 2018
New Revision: 1849273

URL: http://svn.apache.org/viewvc?rev=1849273&view=rev
Log:
PDFBOX-4408: don't assume that numbers in array are continuous

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=1849273&r1=1849272&r2=1849273&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 Wed
Dec 19 07:49:05 2018
@@ -704,6 +704,7 @@ public class PDFMergerUtility
                 {
                     if (destParentTreeNextKey < 0)
                     {
+                        //TODO this is not correct. Needs to search the tree and put last
+ 1 here
                         destParentTreeNextKey = destNumbersArray.size() / 2;
                     }
                     if (destParentTreeNextKey > 0 && srcStructTree != null)
@@ -785,13 +786,24 @@ public class PDFMergerUtility
         }
         if (mergeStructTree)
         {
+            //TODO this code only works with flat number trees.
+            // It should be a PDNumberTreeNode, but that class is broken because
+            // COSBase can't be instanciated and because the tree elements can
+            // be an array or a dictionary
             updatePageReferences(cloner, srcNumbersArray, objMapping);
+            int srcKey = 0;
             for (int i = 0; i < srcNumbersArray.size() / 2; i++)
             {
-                destNumbersArray.add(COSInteger.get(destParentTreeNextKey + i));
+                srcKey = srcNumbersArray.getInt(i * 2);
+                if (srcKey < 0)
+                {
+                    LOG.error("numbers array content on position " + (i * 2) + " should be
an int");
+                    continue;
+                }
+                destNumbersArray.add(COSInteger.get(destParentTreeNextKey + srcKey));
                 destNumbersArray.add(srcNumbersArray.getObject(i * 2 + 1));
             }
-            destParentTreeNextKey += srcNumbersArray.size() / 2;
+            destParentTreeNextKey += srcKey + 1;
             destParentTreeDict.setItem(COSName.NUMS, destNumbersArray);
             PDNumberTreeNode newParentTreeNode = new PDNumberTreeNode(destParentTreeDict,
COSBase.class);
             destStructTree.setParentTree(newParentTreeNode);



Mime
View raw message