Author: tilman
Date: Sat May 17 10:13:10 2025
New Revision: 1925613

URL: http://svn.apache.org/viewvc?rev=1925613&view=rev
Log:
PDFBOX-6009: use one pageDictMap for each destination document and make a list 
of it for postprocessing

Modified:
    
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/multipdf/Splitter.java

Modified: 
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/multipdf/Splitter.java
URL: 
http://svn.apache.org/viewvc/pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/multipdf/Splitter.java?rev=1925613&r1=1925612&r2=1925613&view=diff
==============================================================================
--- 
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/multipdf/Splitter.java
 (original)
+++ 
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/multipdf/Splitter.java
 Sat May 17 10:13:10 2025
@@ -80,7 +80,8 @@ public class Splitter
     private int startPage = Integer.MIN_VALUE;
     private int endPage = Integer.MAX_VALUE;
     private List<PDDocument> destinationDocuments;
-    private Map<COSDictionary, COSDictionary> pageDictMap;
+    private Map<COSDictionary, COSDictionary> pageDictMap; // map old page => 
new page for the current destination document
+    private List<Map<COSDictionary, COSDictionary>> pageDictMaps; // list of 
these maps for all destination documents
     private Map<COSDictionary, COSDictionary> structDictMap;
     private Map<COSDictionary, COSDictionary> annotDictMap;
     private Map<PDPageDestination,PDPage> destToFixMap;
@@ -127,7 +128,7 @@ public class Splitter
         currentPageNumber = 0;
         destinationDocuments = new ArrayList<>();
         sourceDocument = document;
-        pageDictMap = new HashMap<>();
+        pageDictMaps = new ArrayList<>();
         destToFixMap = new HashMap<>();
         annotDictMap = new HashMap<>();
         idSet = new HashSet<>();
@@ -135,8 +136,10 @@ public class Splitter
 
         processPages();
 
-        for (PDDocument destinationDocument : destinationDocuments)
+        for (int i = 0; i < destinationDocuments.size(); ++i)
         {
+            PDDocument destinationDocument = destinationDocuments.get(i);
+            pageDictMap = pageDictMaps.get(i);
             cloneStructureTree(destinationDocument);
             fixDestinations(destinationDocument);
         }
@@ -178,7 +181,8 @@ public class Splitter
     }
 
     /**
-     * Clone the structure tree from the source to the current destination 
document.
+     * Clone the structure tree from the source to the current destination 
document. This must be
+     * called after all pages are processed.
      *
      * @param destinationDocument
      * @throws IOException 
@@ -651,6 +655,8 @@ public class Splitter
         {
             currentDestinationDocument = createNewDocument();
             destinationDocuments.add(currentDestinationDocument);
+            pageDictMap = new HashMap<>();
+            pageDictMaps.add(pageDictMap);
         }
     }
 


Reply via email to