pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1850037 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java
Date Mon, 31 Dec 2018 11:40:00 GMT
Author: tilman
Date: Mon Dec 31 11:39:59 2018
New Revision: 1850037

URL: http://svn.apache.org/viewvc?rev=1850037&view=rev
Log:
PDFBOX-4003: add convenience method to get the whole number tree as a map

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=1850037&r1=1850036&r2=1850037&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
Dec 31 11:39:59 2018
@@ -53,6 +53,7 @@ import org.apache.pdfbox.pdmodel.PDPage;
 import org.apache.pdfbox.pdmodel.PDResources;
 import org.apache.pdfbox.pdmodel.PDStructureElementNameTreeNode;
 import org.apache.pdfbox.pdmodel.PageMode;
+import org.apache.pdfbox.pdmodel.common.COSObjectable;
 import org.apache.pdfbox.pdmodel.common.PDDestinationOrAction;
 import org.apache.pdfbox.pdmodel.common.PDMetadata;
 import org.apache.pdfbox.pdmodel.common.PDNameTreeNode;
@@ -894,6 +895,7 @@ public class PDFMergerUtility
     }
 
     // PDNameTreeNode.getNames() only brings one level, this is why we need this
+    // might be made public at a later time, or integrated into PDNameTreeNode with template.
     static Map<String, PDStructureElement> getIDTreeAsMap(PDNameTreeNode<PDStructureElement>
idTree)
             throws IOException
     {
@@ -913,6 +915,27 @@ public class PDFMergerUtility
         return names;
     }
 
+    // PDNumberTreeNode.getNumbers() only brings one level, this is why we need this
+    // might be made public at a later time, or integrated into PDNumberTreeNode.
+    static Map<Integer, COSObjectable> getNumberTreeAsMap(PDNumberTreeNode tree)
+            throws IOException
+    {
+        Map<Integer, COSObjectable> numbers = tree.getNumbers();
+        if (numbers == null)
+        {
+            numbers = new LinkedHashMap<Integer, COSObjectable>();
+        }
+        List<PDNumberTreeNode> kids = tree.getKids();
+        if (kids != null)
+        {
+            for (PDNumberTreeNode kid : kids)
+            {
+                numbers.putAll(getNumberTreeAsMap(kid));
+            }
+        }
+        return numbers;
+    }
+
     private void mergeRoleMap(PDStructureTreeRoot srcStructTree, PDStructureTreeRoot destStructTree)
     {
         COSDictionary srcDict = srcStructTree.getCOSObject().getCOSDictionary(COSName.ROLE_MAP);



Mime
View raw message