From dev-return-60324-archive-asf-public=cust-asf.ponee.io@pdfbox.apache.org Thu Dec 20 17:19:14 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 25430180648 for ; Thu, 20 Dec 2018 17:19:13 +0100 (CET) Received: (qmail 61844 invoked by uid 500); 20 Dec 2018 16:19:13 -0000 Mailing-List: contact dev-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 dev@pdfbox.apache.org Received: (qmail 61833 invoked by uid 99); 20 Dec 2018 16:19:13 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 20 Dec 2018 16:19:13 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id D6758C8313 for ; Thu, 20 Dec 2018 16:19:12 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -109.5 X-Spam-Level: X-Spam-Status: No, score=-109.5 tagged_above=-999 required=6.31 tests=[ENV_AND_HDR_SPF_MATCH=-0.5, KAM_ASCII_DIVIDERS=0.8, KAM_SHORT=0.001, RCVD_IN_DNSWL_MED=-2.3, SPF_PASS=-0.001, USER_IN_DEF_SPF_WL=-7.5, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id aLgaLH7muzjv for ; Thu, 20 Dec 2018 16:19:11 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTP id B9BAD5F622 for ; Thu, 20 Dec 2018 16:11:01 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id A8031E1013 for ; Thu, 20 Dec 2018 16:11:00 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 4977623FF7 for ; Thu, 20 Dec 2018 16:11:00 +0000 (UTC) Date: Thu, 20 Dec 2018 16:11:00 +0000 (UTC) From: "ASF subversion and git services (JIRA)" To: dev@pdfbox.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (PDFBOX-4407) ParentTree Objects do not match KArray objects after merge MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/PDFBOX-4407?page=3Dcom.atlassia= n.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=3D167= 25982#comment-16725982 ]=20 ASF subversion and git services commented on PDFBOX-4407: --------------------------------------------------------- Commit 1849412 from Tilman Hausherr in branch 'pdfbox/branches/2.0' [ https://svn.apache.org/r1849412 ] PDFBOX-4407: add orphan check for object reference dictionary > ParentTree Objects do not match KArray objects after merge > ---------------------------------------------------------- > > Key: PDFBOX-4407 > URL: https://issues.apache.org/jira/browse/PDFBOX-4407 > Project: PDFBox > Issue Type: Bug > Affects Versions: 3.0.0 PDFBox > Reporter: Dan Anderson > Priority: Major > Labels: StructureTree > Attachments: 4407.patch, reading-order-merged-bad.pdf, reading-or= der.pdf > > > After merging tagged documents together, the second page of the resulting= document is no longer valid.=C2=A0 When the field objects are cloned in PD= FMergerUtility,=C2=A0the new and old objects are stored in a map named=C2= =A0objMapping.=C2=A0 This is used to replace the old references with the ne= w references for the acroform, k array, and annotation list.=C2=A0 However = the ParentTree is not updated to this new object reference.=C2=A0 This resu= lts in the K Array and the Parent Tree having different references to the s= ame object.=C2=A0 This causes issues when using an a11y reader like Jaws, a= nd also causes problems displaying the tags in Adobe DC. > Here is a failing unit test that=C2=A0was created in PDFMergerUtilityTest= to demonstrate the issue.=C2=A0 It was created using an example from W3:= =C2=A0https://www.w3.org/WAI/WCAG20/Techniques/working-examples/PDF3/readin= g-order.pdf > {code:java} > public void testStructureTreeMerge3() throws IOException > { > PDFMergerUtility pdfMergerUtility =3D new PDFMergerUtility(); > PDDocument src =3D PDDocument.load(new File(SRCDIR, "reading-order.pd= f")); > PDDocument dst =3D PDDocument.load(new File(SRCDIR, "reading-order.pd= f")); > pdfMergerUtility.appendDocument(dst, src); > src.close(); > dst.save(new File(TARGETTESTDIR, "reading-order-merged.pdf")); > dst.close(); > PDDocument doc =3D PDDocument.load(new File(TARGETTESTDIR, "reading-o= rder-merged.pdf")); > assertTrue(checkAnnotationMatches(doc.getDocumentCatalog().getStructu= reTreeRoot().getKArray(), doc.getDocumentCatalog().getAcroForm().getFields(= ), (COSArray)doc.getDocumentCatalog().getStructureTreeRoot().getParentTree(= ).getCOSObject().getDictionaryObject(COSName.NUMS))); > } > private boolean checkAnnotationMatches(COSArray kArray, List acr= oformFields, COSArray numbersArray) { > for (int i =3D 0; i < kArray.size(); i++) { > COSBase entry =3D kArray.get(i); > if (entry instanceof COSArray){ > COSArray entryAsArray =3D (COSArray) entry; > if (!checkAnnotationMatches(entryAsArray, acroformFields, num= bersArray)) { > return false; > } > } else if (entry instanceof COSInteger) { > //do nothing, just need to screen these out so next line does= n't blow up > } else if (((COSObject) entry).getObject() instanceof COSDictiona= ry){ > COSDictionary entryDictionary =3D (COSDictionary)((COSObject)= entry).getObject(); > if (entryDictionary.getItem(COSName.K) !=3D null) { > COSBase kids =3D entryDictionary.getItem(COSName.K); > if (kids !=3D null) { > if (kids instanceof COSInteger) { > //do nothing, don't care about marked content tag= s > } else if (kids instanceof COSDictionary) { > COSDictionary kidsAsDictionary =3D (COSDictionary= ) kids; > if (!checkForMatches(kidsAsDictionary.getDictiona= ryObject(COSName.OBJ), acroformFields, numbersArray)) { > return false; > } > } else if (kids instanceof COSArray) { > COSArray kidsAsArray =3D (COSArray) kids; > if (!checkAnnotationMatches(kidsAsArray, acroform= Fields, numbersArray)) { > return false; > } > } > } > } else if (entryDictionary.getDictionaryObject(COSName.OBJ) != =3D null) { > if (!checkForMatches(entryDictionary.getDictionaryObject(= COSName.OBJ), acroformFields, numbersArray)) { > return false; > } > } > } > } > return true; > } > private boolean checkForMatches(COSBase objectReference, List ac= roformFields, COSArray numbersArray) { > boolean result =3D false; > for (PDField field : acroformFields) { > if (field.getCOSObject() =3D=3D objectReference && numbersArray.i= ndexOfObject(objectReference.getCOSObject()) > 0) { > result =3D true; > } > } > return result; > } > {code} -- This message was sent by Atlassian JIRA (v7.6.3#76005) --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org For additional commands, e-mail: dev-help@pdfbox.apache.org