pdfbox-commits mailing list archives

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

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

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

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java?rev=1849274&r1=1849273&r2=1849274&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java
(original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java
Wed Dec 19 07:49:09 2018
@@ -705,6 +705,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)
@@ -786,13 +787,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