You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2024/03/30 12:25:24 UTC
svn commit: r1916653 - /pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/multipdf/Splitter.java
Author: tilman
Date: Sat Mar 30 12:25:23 2024
New Revision: 1916653
URL: http://svn.apache.org/viewvc?rev=1916653&view=rev
Log:
PDFBOX-5792: use a map instead of a set to make sure that the source page (that contains the link to a destination page) is in the current split target document
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=1916653&r1=1916652&r2=1916653&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 Mar 30 12:25:23 2024
@@ -78,7 +78,7 @@ public class Splitter
private Map<COSDictionary, COSDictionary> pageDictMap;
private Map<COSDictionary, COSDictionary> structDictMap;
private Map<COSDictionary, COSDictionary> annotDictMap;
- private Set<PDPageDestination> destToFixSet;
+ private Map<PDPageDestination,PDPage> destToFixMap;
private Set<String> idSet;
private Set<COSName> roleSet;
@@ -123,7 +123,7 @@ public class Splitter
destinationDocuments = new ArrayList<>();
sourceDocument = document;
pageDictMap = new HashMap<>();
- destToFixSet = new HashSet<>();
+ destToFixMap = new HashMap<>();
annotDictMap = new HashMap<>();
idSet = new HashSet<>();
roleSet = new HashSet<>();
@@ -140,25 +140,27 @@ public class Splitter
}
/**
- * Replace the page destinations, if the destination page is in the target document. This must
- * be called after all pages (and its annotations) are processed.
+ * Replace the page destinations, if the source and destination pages are in the target
+ * document. This must be called after all pages (and its annotations) are processed.
*
* @param destinationDocument
*/
private void fixDestinations(PDDocument destinationDocument)
{
PDPageTree pageTree = destinationDocument.getPages();
- for (PDPageDestination pageDestination : destToFixSet)
+ for (Map.Entry<PDPageDestination,PDPage> entry : destToFixMap.entrySet())
{
- if (pageDestination.getPage() == null)
+ PDPageDestination pageDestination = entry.getKey();
+ // Find whether source page is inside or outside
+ PDPage srcPage = entry.getValue();
+ if (pageTree.indexOf(srcPage) < 0)
{
- //TODO avoid NPE until proper solution, see PDFBOX-5792
continue;
}
COSDictionary srcPageDict = pageDestination.getPage().getCOSObject();
COSDictionary dstPageDict = pageDictMap.get(srcPageDict);
PDPage dstPage = new PDPage(dstPageDict);
- // Find whether destination is inside or outside
+ // Find whether destination page is inside or outside
if (pageTree.indexOf(dstPage) >= 0)
{
pageDestination.setPage(dstPage);
@@ -750,7 +752,7 @@ public class Splitter
(PDPageDestination) PDDestination.create(clonedDestinationArray);
// remember the destination to adjust / remove page later
- destToFixSet.add(dstDestination);
+ destToFixMap.put(dstDestination, imported);
if (action != null)
{