pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1849965 - /pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java
Date Sun, 30 Dec 2018 09:37:46 GMT
Author: tilman
Date: Sun Dec 30 09:37:46 2018
New Revision: 1849965

URL: http://svn.apache.org/viewvc?rev=1849965&view=rev
Log:
PDFBOX-4416: merge /IDTree

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=1849965&r1=1849964&r2=1849965&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
Sun Dec 30 09:37:46 2018
@@ -51,6 +51,7 @@ import org.apache.pdfbox.pdmodel.PDDocum
 import org.apache.pdfbox.pdmodel.PDDocumentNameDictionary;
 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.PDDestinationOrAction;
 import org.apache.pdfbox.pdmodel.common.PDMetadata;
@@ -820,6 +821,7 @@ public class PDFMergerUtility
 
             mergeKEntries(cloner, srcStructTree, destStructTree);
             mergeRoleMap(srcStructTree, destStructTree);
+            mergeIDTree(cloner, srcStructTree, destStructTree);
         }
     }
 
@@ -864,6 +866,39 @@ public class PDFMergerUtility
         }
     }
 
+    private void mergeIDTree(PDFCloneUtility cloner,
+            PDStructureTreeRoot srcStructTree,
+            PDStructureTreeRoot destStructTree) throws IOException
+    {
+        PDNameTreeNode<PDStructureElement> srcIDTree = srcStructTree.getIDTree();
+        PDNameTreeNode<PDStructureElement> destIDTree = destStructTree.getIDTree();
+        if (srcIDTree == null)
+        {
+            return;
+        }
+        if (destIDTree == null)
+        {
+            destIDTree = new PDStructureElementNameTreeNode();
+        }
+        Map<String, PDStructureElement> srcNames = getIDTreeAsMap(srcIDTree);
+        Map<String, PDStructureElement> destNames = getIDTreeAsMap(destIDTree);
+        for (Map.Entry<String, PDStructureElement> entry : srcNames.entrySet())
+        {
+            if (destNames.containsKey(entry.getKey()))
+            {
+                LOG.warn("key " + entry.getKey() + " already exists in destination IDTree");
+            }
+            else
+            {
+                destNames.put(entry.getKey(),
+                              new PDStructureElement((COSDictionary) cloner.cloneForNewDocument(entry.getValue().getCOSObject())));
+            }
+        }
+        destIDTree = new PDStructureElementNameTreeNode();
+        destIDTree.setNames(destNames);
+        destStructTree.setIDTree(destIDTree);
+    }
+
     // PDNameTreeNode.getNames() only brings one level, this is why we need this
     static Map<String, PDStructureElement> getIDTreeAsMap(PDNameTreeNode<PDStructureElement>
idTree)
             throws IOException



Mime
View raw message