pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1850119 - /pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PDFMergerUtilityTest.java
Date Tue, 01 Jan 2019 20:59:45 GMT
Author: tilman
Date: Tue Jan  1 20:59:45 2019
New Revision: 1850119

URL: http://svn.apache.org/viewvc?rev=1850119&view=rev
Log:
PDFBOX-4009: Test that ParentTreeNextKey is recalculated correctly

Modified:
    pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PDFMergerUtilityTest.java

Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PDFMergerUtilityTest.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PDFMergerUtilityTest.java?rev=1850119&r1=1850118&r2=1850119&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PDFMergerUtilityTest.java
(original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PDFMergerUtilityTest.java
Tue Jan  1 20:59:45 2019
@@ -355,9 +355,6 @@ public class PDFMergerUtilityTest extend
         // ParentTreeNextKey should be 321 but PDF has a higher value
         assertEquals(408, structureTreeRoot.getParentTreeNextKey());
 
-        //TODO if we delete ParentTreeNextKey and merge 000314.pdf with an empty file then

-        // the new key should be 328
-        
         pdfMergerUtility.appendDocument(dst, src);
         src.close();
         dst.save(new File(TARGETTESTDIR, "PDFBOX-4418-merged.pdf"));
@@ -380,6 +377,30 @@ public class PDFMergerUtilityTest extend
     }
 
     /**
+     * PDFBOX-4009: Test that ParentTreeNextKey is recalculated correctly.
+     */
+    public void testMissingParentTreeNextKey() throws IOException
+    {
+        PDFMergerUtility pdfMergerUtility = new PDFMergerUtility();
+        PDDocument src = PDDocument.load(new File(TARGETPDFDIR, "PDFBOX-4418-000314.pdf"));
+        PDDocument dst = PDDocument.load(new File(TARGETPDFDIR, "PDFBOX-4418-000314.pdf"));
+        System.out.println(dst.getDocumentCatalog().getStructureTreeRoot().getParentTreeNextKey());
+        // existing numbers are 321..327; ParentTreeNextKey is 408. 
+        // After deletion, it is recalculated in the merge 328.
+        // That value is added to all numbers of the destination,
+        // so the new numbers should be 321+328..327+328, i.e. 649..655,
+        // and this ParentTreeNextKey is 656 at the end.
+        dst.getDocumentCatalog().getStructureTreeRoot().getCOSObject().removeItem(COSName.PARENT_TREE_NEXT_KEY);
+        pdfMergerUtility.appendDocument(dst, src);
+        src.close();
+        dst.save(new File(TARGETTESTDIR, "PDFBOX-4418-000314-merged.pdf"));
+        dst.close();
+        dst = PDDocument.load(new File(TARGETTESTDIR, "PDFBOX-4418-000314-merged.pdf"));
+        assertEquals(656, dst.getDocumentCatalog().getStructureTreeRoot().getParentTreeNextKey());
+        dst.close();
+    }
+
+    /**
      * PDFBOX-4416: Test merging of /IDTree
      * <br>
      * PDFBOX-4009: test merging to empty destination



Mime
View raw message