You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2014/12/22 11:30:41 UTC

svn commit: r1647283 - /pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/Splitter.java

Author: lehmi
Date: Mon Dec 22 10:30:41 2014
New Revision: 1647283

URL: http://svn.apache.org/r1647283
Log:
PDFBOX-785: remove all pages within annotations to avoid the import of unneeded resources

Modified:
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/Splitter.java

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/Splitter.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/Splitter.java?rev=1647283&r1=1647282&r2=1647283&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/Splitter.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/Splitter.java Mon Dec 22 10:30:41 2014
@@ -18,9 +18,12 @@ package org.apache.pdfbox.util;
 
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.pdfbox.pdmodel.PDPage;
+import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation;
+import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationLink;
+import org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination.PDDestination;
+import org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination.PDPageDestination;
 
 import java.io.IOException;
-
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
@@ -246,6 +249,32 @@ public class Splitter
         // only the resources of the page will be copied
         imported.setResources( page.getResources() );
         imported.setRotation( page.findRotation() );
+        // remove page links to avoid copying not needed resources 
+        processAnnotations(imported);
         pageNumber++;
     }
+    
+    private void processAnnotations(PDPage imported) throws IOException
+    {
+        List<PDAnnotation> annotations = imported.getAnnotations();
+        for (PDAnnotation annotation : annotations)
+        {
+            if (annotation instanceof PDAnnotationLink)
+            {
+                PDAnnotationLink link = (PDAnnotationLink)annotation;   
+                PDDestination destination = link.getDestination();
+                if (destination instanceof PDPageDestination)
+                {
+                    // TODO preserve links to pages within the splitted result  
+                    link.setDestination(null);
+                }
+            }
+            else
+            {
+                // TODO preserve links to pages within the splitted result  
+                annotation.setPage(null);
+            }
+        }
+    }
+
 }