From dev-return-60256-archive-asf-public=cust-asf.ponee.io@pdfbox.apache.org Mon Dec 17 22:03:05 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 DCFB5180652 for ; Mon, 17 Dec 2018 22:03:04 +0100 (CET) Received: (qmail 93619 invoked by uid 500); 17 Dec 2018 21:03:04 -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 93608 invoked by uid 99); 17 Dec 2018 21:03:03 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 17 Dec 2018 21:03:03 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 91434180588 for ; Mon, 17 Dec 2018 21:03:03 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -110.3 X-Spam-Level: X-Spam-Status: No, score=-110.3 tagged_above=-999 required=6.31 tests=[ENV_AND_HDR_SPF_MATCH=-0.5, 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 (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id m3OLxMzTZByl for ; Mon, 17 Dec 2018 21:03:02 +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 70A7460E8F for ; Mon, 17 Dec 2018 21:03: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 83AFFE00C9 for ; Mon, 17 Dec 2018 21:03: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 087B723FC7 for ; Mon, 17 Dec 2018 21:03:00 +0000 (UTC) Date: Mon, 17 Dec 2018 21:03:00 +0000 (UTC) From: "Dan Anderson (JIRA)" To: dev@pdfbox.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Created] (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 Dan Anderson created PDFBOX-4407: ------------------------------------ Summary: 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.2 JBIG2 Reporter: Dan Anderson Attachments: reading-order.pdf After merging tagged documents together, the second page of the resulting d= ocument is no longer valid.=C2=A0 When the field objects are cloned in PDFM= ergerUtility,=C2=A0the new and old objects are stored in a map named=C2=A0o= bjMapping.=C2=A0 This is used to replace the old references with the new re= ferences for the acroform, k array, and annotation list.=C2=A0 However the = ParentTree is not updated to this new object reference.=C2=A0 This results = in the K Array and the Parent Tree having different references to the same = object.=C2=A0 This causes issues when using an a11y reader like Jaws, and a= lso causes problems displaying the tags in Adobe DC. Here is a failing unit test that=C2=A0was created in PDFMergerUtilityTest t= o demonstrate the issue.=C2=A0 It was created using an example from W3:=C2= =A0https://www.w3.org/WAI/WCAG20/Techniques/working-examples/PDF3/reading-o= rder.pdf {code:java} public void testStructureTreeMerge3() throws IOException { PDFMergerUtility pdfMergerUtility =3D new PDFMergerUtility(); PDDocument src =3D PDDocument.load(new File(SRCDIR, "reading-order.pdf"= )); PDDocument dst =3D PDDocument.load(new File(SRCDIR, "reading-order.pdf"= )); 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-ord= er-merged.pdf")); assertTrue(checkAnnotationMatches(doc.getDocumentCatalog().getStructure= TreeRoot().getKArray(), doc.getDocumentCatalog().getAcroForm().getFields(),= (COSArray)doc.getDocumentCatalog().getStructureTreeRoot().getParentTree().= getCOSObject().getDictionaryObject(COSName.NUMS))); } private boolean checkAnnotationMatches(COSArray kArray, List acrof= ormFields, 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, numbe= rsArray)) { return false; } } else if (entry instanceof COSInteger) { //do nothing, just need to screen these out so next line doesn'= t blow up } else if (((COSObject) entry).getObject() instanceof COSDictionary= ){ COSDictionary entryDictionary =3D (COSDictionary)((COSObject) e= ntry).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 tags } else if (kids instanceof COSDictionary) { COSDictionary kidsAsDictionary =3D (COSDictionary) = kids; if (!checkForMatches(kidsAsDictionary.getDictionary= Object(COSName.OBJ), acroformFields, numbersArray)) { return false; } } else if (kids instanceof COSArray) { COSArray kidsAsArray =3D (COSArray) kids; if (!checkAnnotationMatches(kidsAsArray, acroformFi= elds, numbersArray)) { return false; } } } } else if (entryDictionary.getDictionaryObject(COSName.OBJ) != =3D null) { if (!checkForMatches(entryDictionary.getDictionaryObject(CO= SName.OBJ), acroformFields, numbersArray)) { return false; } } } } return true; } private boolean checkForMatches(COSBase objectReference, List acro= formFields, COSArray numbersArray) { boolean result =3D false; for (PDField field : acroformFields) { if (field.getCOSObject() =3D=3D objectReference && numbersArray.ind= exOfObject(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