Skip to content

Commit

Permalink
PDFBOX-5950: add test with 2 files from issue 515
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1923732 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
THausherr committed Feb 11, 2025
1 parent f68e58c commit 789c0bb
Showing 1 changed file with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@
import org.apache.pdfbox.pdmodel.PDDocumentCatalog;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.PDPageTree;
import org.apache.pdfbox.pdmodel.PDResources;
import org.apache.pdfbox.pdmodel.common.COSObjectable;
import org.apache.pdfbox.pdmodel.common.PDNameTreeNode;
import org.apache.pdfbox.pdmodel.common.PDNumberTreeNode;
import org.apache.pdfbox.pdmodel.documentinterchange.logicalstructure.PDStructureElement;
import org.apache.pdfbox.pdmodel.documentinterchange.logicalstructure.PDStructureNode;
import org.apache.pdfbox.pdmodel.documentinterchange.logicalstructure.PDStructureTreeRoot;
import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject;
import org.apache.pdfbox.pdmodel.interactive.action.PDAction;
import org.apache.pdfbox.pdmodel.interactive.action.PDActionGoTo;
import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation;
Expand Down Expand Up @@ -1352,4 +1354,33 @@ void testOutlinesSelfParent() throws IOException
assertEquals(2, mergedDoc.getNumberOfPages());
}
}
}

/**
* PDFBOX-515 / PDFBOX-5950: test merging of two files where one file has a stream deep down in
* the info dictionary (Info/ImPDF/Images/Kids/[0]). This test will pass only if the source file
* isn't closed prematurely, or if deep cloning is applied.
*
* @throws IOException
*/
@Test
void testPDFBox515() throws IOException
{
PDFMergerUtility pdfMergerUtility = new PDFMergerUtility();
pdfMergerUtility.addSource(new File(TARGETPDFDIR, "ComSquare1.pdf"));
pdfMergerUtility.addSource(new File(TARGETPDFDIR, "Ghostscript1.pdf"));
pdfMergerUtility.setDestinationFileName(TARGETTESTDIR + "PDFBOX-515-result.pdf");
pdfMergerUtility.mergeDocuments(IOUtils.createMemoryOnlyStreamCache());

try (PDDocument mergedDoc = Loader.loadPDF(new File(TARGETTESTDIR, "PDFBOX-515-result.pdf")))
{
assertEquals(2, mergedDoc.getNumberOfPages());
COSDictionary imageDict = (COSDictionary) mergedDoc.getDocumentInformation().getCOSObject().
getCOSDictionary(COSName.getPDFName("ImPDF")).
getCOSDictionary(COSName.getPDFName("Images")).
getCOSArray(COSName.KIDS).getObject(0);
PDImageXObject imageXObject = (PDImageXObject) PDImageXObject.createXObject(imageDict, new PDResources());
assertEquals(909, imageXObject.getWidth());
assertEquals(233, imageXObject.getHeight());
}
}
}

0 comments on commit 789c0bb

Please sign in to comment.