2015-03-17 14:26 GMT+01:00 Morales-Martin, Kristina <[email protected]>:
> In our use of the org.apache.pdfbox.util.Splitter class to split a PDF 
> document according to top level bookmarks,
> we have observed that the newly created documents do not retain the existing 
> Acrobat/PDF version of the original document.
> (Splitter#createNewDocument()).
>
> Can experienced users/developers direct us to samples or other resources that 
> show how this can be achieved?

Hello Kristina,
can you try the attached patch to org.apache.pdfbox.multipdf.Splitter?
It should copy the PDF version of the source to the newly created documents.

Note that PDFBox always sets the version in the header to 1.4 and this
only updates the /Version entry in the Document Catalog. This should
be enough (at least it works with Adobe Reader).

Best
   Martin
Index: Splitter.java
===================================================================
--- Splitter.java	(Revision 1667310)
+++ Splitter.java	(Arbeitskopie)
@@ -16,6 +16,10 @@
  */
 package org.apache.pdfbox.multipdf;
 
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.pdfbox.pdmodel.PDPage;
 import org.apache.pdfbox.pdmodel.interactive.action.PDAction;
@@ -25,10 +29,6 @@
 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.List;
-
 /**
  * Split a document into several other documents.
  *
@@ -131,10 +131,7 @@
                 {
                     break;
                 }
-                else
-                {
-                    currentPageNumber++;
-                }
+                currentPageNumber++;
             }
         }
     }
@@ -179,6 +176,7 @@
      * @return the newly created PDDocument. 
      * @throws IOException If there is an problem creating the new document.
      */
+    @SuppressWarnings("unused")
     protected PDDocument createNewDocument() throws IOException
     {
         PDDocument document = new PDDocument();
@@ -185,6 +183,8 @@
         document.setDocumentInformation(getSourceDocument().getDocumentInformation());
         document.getDocumentCatalog().setViewerPreferences(
                 getSourceDocument().getDocumentCatalog().getViewerPreferences());
+        document.getDocumentCatalog().setVersion(
+                getSourceDocument().getDocumentCatalog().getVersion());
         return document;
     }
 
@@ -209,7 +209,7 @@
         processAnnotations(imported);
     }
 
-    private void processAnnotations(PDPage imported) throws IOException
+    private static void processAnnotations(PDPage imported) throws IOException
     {
         List<PDAnnotation> annotations = imported.getAnnotations();
         for (PDAnnotation annotation : annotations)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to