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 2021/05/29 03:00:55 UTC

svn commit: r1890301 - /pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PDFMergerUtilityTest.java

Author: tilman
Date: Sat May 29 03:00:55 2021
New Revision: 1890301

URL: http://svn.apache.org/viewvc?rev=1890301&view=rev
Log:
PDFBOX-5198: add test

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

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=1890301&r1=1890300&r2=1890301&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 Sat May 29 03:00:55 2021
@@ -684,6 +684,65 @@ public class PDFMergerUtilityTest extend
         assertTrue(outFile.delete());
     }
 
+
+    /**
+     * Check that there is a top level Document and Parts below in a merge of 2 documents.
+     *
+     * @param file
+     * @throws IOException 
+     */
+    public void testPDFBox5198_2() throws IOException
+    {
+        PDFMergerUtility pdfMergerUtility = new PDFMergerUtility();
+        pdfMergerUtility.addSource(new File(SRCDIR, "PDFA3A.pdf"));
+        pdfMergerUtility.addSource(new File(SRCDIR, "PDFA3A.pdf"));
+        pdfMergerUtility.setDestinationFileName(TARGETTESTDIR + "PDFA3A-merged2.pdf");
+        pdfMergerUtility.mergeDocuments(MemoryUsageSetting.setupMainMemoryOnly());
+
+        checkParts(new File(TARGETTESTDIR + "PDFA3A-merged2.pdf"));
+    }
+    
+    /**
+     * Check that there is a top level Document and Parts below in a merge of 3 documents.
+     *
+     * @param file
+     * @throws IOException 
+     */
+    public void testPDFBox5198_3() throws IOException
+    {
+        PDFMergerUtility pdfMergerUtility = new PDFMergerUtility();
+        pdfMergerUtility.addSource(new File(SRCDIR, "PDFA3A.pdf"));
+        pdfMergerUtility.addSource(new File(SRCDIR, "PDFA3A.pdf"));
+        pdfMergerUtility.addSource(new File(SRCDIR, "PDFA3A.pdf"));
+        pdfMergerUtility.setDestinationFileName(TARGETTESTDIR + "PDFA3A-merged3.pdf");
+        pdfMergerUtility.mergeDocuments(MemoryUsageSetting.setupMainMemoryOnly());
+
+        checkParts(new File(TARGETTESTDIR + "PDFA3A-merged3.pdf"));
+    }
+
+    /**
+     * Check that there is a top level Document and Parts below.
+     * @param file
+     * @throws IOException 
+     */
+    private void checkParts(File file) throws IOException
+    {
+        PDDocument doc = PDDocument.load(file);
+        PDStructureTreeRoot structureTreeRoot = doc.getDocumentCatalog().getStructureTreeRoot();
+        COSDictionary topDict = (COSDictionary) structureTreeRoot.getK();
+        assertEquals(COSName.DOCUMENT, topDict.getItem(COSName.S));
+        assertEquals(structureTreeRoot.getCOSObject(), topDict.getCOSDictionary(COSName.P));
+        COSArray kArray = topDict.getCOSArray(COSName.K);
+        assertEquals(doc.getNumberOfPages(), kArray.size());
+        for (int i = 0; i < kArray.size(); ++i)
+        {
+            COSDictionary dict = (COSDictionary) kArray.getObject(i);
+            assertEquals(COSName.PART, dict.getItem(COSName.S));
+            assertEquals(topDict, dict.getCOSDictionary(COSName.P));
+        }
+        doc.close();
+    }
+
     private void checkForPageOrphans(PDDocument doc) throws IOException
     {
         // check for orphan pages in the StructTreeRoot/K, StructTreeRoot/ParentTree and