pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1849857 - /pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java
Date Fri, 28 Dec 2018 14:06:04 GMT
Author: tilman
Date: Fri Dec 28 14:06:04 2018
New Revision: 1849857

URL: http://svn.apache.org/viewvc?rev=1849857&view=rev
Log:
PDFBOX-4416: add convenience method to get the IDTree as a map

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=1849857&r1=1849856&r2=1849857&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
Fri Dec 28 14:06:04 2018
@@ -26,6 +26,7 @@ import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -53,9 +54,11 @@ import org.apache.pdfbox.pdmodel.PDResou
 import org.apache.pdfbox.pdmodel.PageMode;
 import org.apache.pdfbox.pdmodel.common.PDDestinationOrAction;
 import org.apache.pdfbox.pdmodel.common.PDMetadata;
+import org.apache.pdfbox.pdmodel.common.PDNameTreeNode;
 import org.apache.pdfbox.pdmodel.common.PDNumberTreeNode;
 import org.apache.pdfbox.pdmodel.common.PDStream;
 import org.apache.pdfbox.pdmodel.documentinterchange.logicalstructure.PDMarkInfo;
+import org.apache.pdfbox.pdmodel.documentinterchange.logicalstructure.PDStructureElement;
 import org.apache.pdfbox.pdmodel.documentinterchange.logicalstructure.PDStructureTreeRoot;
 import org.apache.pdfbox.pdmodel.graphics.color.PDOutputIntent;
 import org.apache.pdfbox.pdmodel.interactive.action.PDActionGoTo;
@@ -828,6 +831,26 @@ public class PDFMergerUtility
         }
     }
 
+    // PDNameTreeNode.getNames() only brings one level, this is why we need this
+    static Map<String, PDStructureElement> getIDTreeAsMap(PDNameTreeNode<PDStructureElement>
idTree)
+            throws IOException
+    {
+        Map<String, PDStructureElement> names = idTree.getNames();
+        if (names == null)
+        {
+            names = new LinkedHashMap<String, PDStructureElement>();
+        }
+        List<PDNameTreeNode<PDStructureElement>> kids = idTree.getKids();
+        if (kids != null)
+        {
+            for (PDNameTreeNode<PDStructureElement> kid : kids)
+            {
+                names.putAll(getIDTreeAsMap(kid));
+            }
+        }
+        return names;
+    }
+
     private void mergeRoleMap(PDStructureTreeRoot srcStructTree, PDStructureTreeRoot destStructTree)
     {
         COSDictionary srcDict = srcStructTree.getCOSObject().getCOSDictionary(COSName.ROLE_MAP);



Mime
View raw message