pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1850978 - in /pdfbox/branches/2.0/pdfbox/src: main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java test/java/org/apache/pdfbox/multipdf/PDFMergerUtilityTest.java
Date Thu, 10 Jan 2019 20:18:34 GMT
Author: tilman
Date: Thu Jan 10 20:18:34 2019
New Revision: 1850978

URL: http://svn.apache.org/viewvc?rev=1850978&view=rev
Log:
PDFBOX-4429: remove bogus StructParent(s) + test

Modified:
    pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java
    pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PDFMergerUtilityTest.java

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java?rev=1850978&r1=1850977&r2=1850978&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java
(original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java
Thu Jan 10 20:18:34 2019
@@ -706,6 +706,15 @@ public class PDFMergerUtility
             destStructTree = new PDStructureTreeRoot();
             destCatalog.setStructureTreeRoot(destStructTree);
             destStructTree.setParentTree(new PDNumberTreeNode(PDParentTreeValue.class));
+            // PDFBOX-4429: remove bogus StructParent(s)
+            for (PDPage page : destCatalog.getPages())
+            {
+                page.getCOSObject().removeItem(COSName.STRUCT_PARENTS);
+                for (PDAnnotation ann : page.getAnnotations())
+                {
+                    ann.getCOSObject().removeItem(COSName.STRUCT_PARENT);
+                }
+            }
         }
         if (destStructTree != null)
         {
@@ -745,6 +754,15 @@ public class PDFMergerUtility
         for (PDPage page : srcCatalog.getPages())
         {
             PDPage newPage = new PDPage((COSDictionary) cloner.cloneForNewDocument(page.getCOSObject()));
+            if (!mergeStructTree)
+            {
+                // PDFBOX-4429: remove bogus StructParent(s)
+                newPage.getCOSObject().removeItem(COSName.STRUCT_PARENTS);
+                for (PDAnnotation ann : newPage.getAnnotations())
+                {
+                    ann.getCOSObject().removeItem(COSName.STRUCT_PARENT);
+                }
+            }
             newPage.setCropBox(page.getCropBox());
             newPage.setMediaBox(page.getMediaBox());
             newPage.setRotation(page.getRotation());

Modified: pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PDFMergerUtilityTest.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PDFMergerUtilityTest.java?rev=1850978&r1=1850977&r2=1850978&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PDFMergerUtilityTest.java
(original)
+++ pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PDFMergerUtilityTest.java
Thu Jan 10 20:18:34 2019
@@ -482,6 +482,48 @@ public class PDFMergerUtilityTest extend
     }
 
     /**
+     * PDFBOX-4429: merge into destination that has /StructParent(s) entries in the destination
file
+     * but no structure tree.
+     *
+     * @throws IOException
+     */
+    public void testMergeBogusStructParents1() throws IOException
+    {
+        PDFMergerUtility pdfMergerUtility = new PDFMergerUtility();
+        PDDocument src = PDDocument.load(new File(TARGETPDFDIR, "PDFBOX-4408.pdf"));
+        PDDocument dst = PDDocument.load(new File(TARGETPDFDIR, "PDFBOX-4408.pdf"));
+        dst.getDocumentCatalog().setStructureTreeRoot(null);
+        dst.getPage(0).setStructParents(9999);
+        dst.getPage(0).getAnnotations().get(0).setStructParent(9998);
+        pdfMergerUtility.appendDocument(dst, src);
+        checkWithNumberTree(dst);
+        checkForPageOrphans(dst);
+        src.close();
+        dst.close();
+    }
+
+    /**
+     * PDFBOX-4429: merge into destination that has /StructParent(s) entries in the source
file but
+     * no structure tree.
+     *
+     * @throws IOException
+     */
+    public void testMergeBogusStructParents2() throws IOException
+    {
+        PDFMergerUtility pdfMergerUtility = new PDFMergerUtility();
+        PDDocument src = PDDocument.load(new File(TARGETPDFDIR, "PDFBOX-4408.pdf"));
+        PDDocument dst = PDDocument.load(new File(TARGETPDFDIR, "PDFBOX-4408.pdf"));
+        src.getDocumentCatalog().setStructureTreeRoot(null);
+        src.getPage(0).setStructParents(9999);
+        src.getPage(0).getAnnotations().get(0).setStructParent(9998);
+        pdfMergerUtility.appendDocument(dst, src);
+        checkWithNumberTree(dst);
+        checkForPageOrphans(dst);
+        src.close();
+        dst.close();
+    }
+
+    /**
      * Test of the parent tree. Didn't work before PDFBOX-4003 because of incompatible class
for
      * PDNumberTreeNode.
      *



Mime
View raw message