From commits-return-12448-archive-asf-public=cust-asf.ponee.io@pdfbox.apache.org Thu Apr 19 19:30:11 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 9AB00180638 for ; Thu, 19 Apr 2018 19:30:10 +0200 (CEST) Received: (qmail 30941 invoked by uid 500); 19 Apr 2018 17:30:09 -0000 Mailing-List: contact commits-help@pdfbox.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@pdfbox.apache.org Delivered-To: mailing list commits@pdfbox.apache.org Received: (qmail 30932 invoked by uid 99); 19 Apr 2018 17:30:09 -0000 Received: from Unknown (HELO svn01-us-west.apache.org) (209.188.14.144) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 19 Apr 2018 17:30:09 +0000 Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id 0EC3D3A00B7 for ; Thu, 19 Apr 2018 17:30:09 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1829578 - /pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PDFMergerUtilityTest.java Date: Thu, 19 Apr 2018 17:30:09 -0000 To: commits@pdfbox.apache.org From: tilman@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20180419173009.0EC3D3A00B7@svn01-us-west.apache.org> Author: tilman Date: Thu Apr 19 17:30:08 2018 New Revision: 1829578 URL: http://svn.apache.org/viewvc?rev=1829578&view=rev Log: PDFBOX-3999: add test that closes one source file with flattened annotations after merging but before the destination file is saved 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=1829578&r1=1829577&r2=1829578&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 Apr 19 17:30:08 2018 @@ -174,10 +174,42 @@ public class PDFMergerUtilityTest extend PDDocument dst = PDDocument.load(new File(TARGETPDFDIR, "PDFBOX-3999-GeneralForbearance.pdf")); pdfMergerUtility.appendDocument(dst, src); src.close(); - dst.save(new File(TARGETTESTDIR, "PDFBOX-3999-GovFormPreFlattened-merged.pdf")); + dst.save(new File(TARGETTESTDIR, "PDFBOX-3999-GeneralForbearance-merged.pdf")); dst.close(); - PDDocument doc = PDDocument.load(new File(TARGETTESTDIR, "PDFBOX-3999-GovFormPreFlattened-merged.pdf")); + PDDocument doc = PDDocument.load(new File(TARGETTESTDIR, "PDFBOX-3999-GeneralForbearance-merged.pdf")); + PDPageTree pageTree = doc.getPages(); + + // check for orphan pages in the StructTreeRoot/K and StructTreeRoot/ParentTree trees. + PDStructureTreeRoot structureTreeRoot = doc.getDocumentCatalog().getStructureTreeRoot(); + checkElement(pageTree, structureTreeRoot.getParentTree().getCOSObject()); + checkElement(pageTree, structureTreeRoot.getK()); + } + + /** + * PDFBOX-3999: check that no streams are kept from the source document by the destination + * document, despite orphan annotations remaining in the structure tree. + * + * @throws IOException + */ + public void testStructureTreeMerge2() throws IOException + { + PDFMergerUtility pdfMergerUtility = new PDFMergerUtility(); + PDDocument doc = PDDocument.load(new File(TARGETPDFDIR, "PDFBOX-3999-GeneralForbearance.pdf")); + doc.getDocumentCatalog().getAcroForm().flatten(); + doc.save(new File(TARGETTESTDIR, "PDFBOX-3999-GeneralForbearance-Flattened.pdf")); + doc.close(); + + PDDocument src = PDDocument.load(new File(TARGETTESTDIR, "PDFBOX-3999-GeneralForbearance-flattened.pdf")); + PDDocument dst = PDDocument.load(new File(TARGETTESTDIR, "PDFBOX-3999-GeneralForbearance-flattened.pdf")); + pdfMergerUtility.appendDocument(dst, src); + // before solving PDFBOX-3999, the close() below brought + // IOException: COSStream has been closed and cannot be read. + src.close(); + dst.save(new File(TARGETTESTDIR, "PDFBOX-3999-GeneralForbearance-flattened-merged.pdf")); + dst.close(); + + doc = PDDocument.load(new File(TARGETTESTDIR, "PDFBOX-3999-GeneralForbearance-flattened-merged.pdf")); PDPageTree pageTree = doc.getPages(); // check for orphan pages in the StructTreeRoot/K and StructTreeRoot/ParentTree trees.