4040import org .apache .pdfbox .pdmodel .PDDocumentCatalog ;
4141import org .apache .pdfbox .pdmodel .PDPage ;
4242import org .apache .pdfbox .pdmodel .PDPageTree ;
43+ import org .apache .pdfbox .pdmodel .PDResources ;
4344import org .apache .pdfbox .pdmodel .common .COSObjectable ;
4445import org .apache .pdfbox .pdmodel .common .PDNameTreeNode ;
4546import org .apache .pdfbox .pdmodel .common .PDNumberTreeNode ;
4647import org .apache .pdfbox .pdmodel .documentinterchange .logicalstructure .PDStructureElement ;
4748import org .apache .pdfbox .pdmodel .documentinterchange .logicalstructure .PDStructureNode ;
4849import org .apache .pdfbox .pdmodel .documentinterchange .logicalstructure .PDStructureTreeRoot ;
50+ import org .apache .pdfbox .pdmodel .graphics .image .PDImageXObject ;
4951import org .apache .pdfbox .pdmodel .interactive .action .PDAction ;
5052import org .apache .pdfbox .pdmodel .interactive .action .PDActionGoTo ;
5153import org .apache .pdfbox .pdmodel .interactive .annotation .PDAnnotation ;
@@ -1352,4 +1354,33 @@ void testOutlinesSelfParent() throws IOException
13521354 assertEquals (2 , mergedDoc .getNumberOfPages ());
13531355 }
13541356 }
1355- }
1357+
1358+ /**
1359+ * PDFBOX-515 / PDFBOX-5950: test merging of two files where one file has a stream deep down in
1360+ * the info dictionary (Info/ImPDF/Images/Kids/[0]). This test will pass only if the source file
1361+ * isn't closed prematurely, or if deep cloning is applied.
1362+ *
1363+ * @throws IOException
1364+ */
1365+ @ Test
1366+ void testPDFBox515 () throws IOException
1367+ {
1368+ PDFMergerUtility pdfMergerUtility = new PDFMergerUtility ();
1369+ pdfMergerUtility .addSource (new File (TARGETPDFDIR , "ComSquare1.pdf" ));
1370+ pdfMergerUtility .addSource (new File (TARGETPDFDIR , "Ghostscript1.pdf" ));
1371+ pdfMergerUtility .setDestinationFileName (TARGETTESTDIR + "PDFBOX-515-result.pdf" );
1372+ pdfMergerUtility .mergeDocuments (IOUtils .createMemoryOnlyStreamCache ());
1373+
1374+ try (PDDocument mergedDoc = Loader .loadPDF (new File (TARGETTESTDIR , "PDFBOX-515-result.pdf" )))
1375+ {
1376+ assertEquals (2 , mergedDoc .getNumberOfPages ());
1377+ COSDictionary imageDict = (COSDictionary ) mergedDoc .getDocumentInformation ().getCOSObject ().
1378+ getCOSDictionary (COSName .getPDFName ("ImPDF" )).
1379+ getCOSDictionary (COSName .getPDFName ("Images" )).
1380+ getCOSArray (COSName .KIDS ).getObject (0 );
1381+ PDImageXObject imageXObject = (PDImageXObject ) PDImageXObject .createXObject (imageDict , new PDResources ());
1382+ assertEquals (909 , imageXObject .getWidth ());
1383+ assertEquals (233 , imageXObject .getHeight ());
1384+ }
1385+ }
1386+ }
0 commit comments