[ https://issues.apache.org/jira/browse/PDFBOX-4751?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Andreas Lehmkühler reopened PDFBOX-4751: ---------------------------------------- > Removing field / annotation does not work > ----------------------------------------- > > Key: PDFBOX-4751 > URL: https://issues.apache.org/jira/browse/PDFBOX-4751 > Project: PDFBox > Issue Type: Bug > Components: AcroForm > Affects Versions: 2.0.18 > Environment: macOS Mojave 10.14.6 > Reporter: Jesse > Assignee: Maruan Sahyoun > Priority: Minor > Fix For: 2.0.20, 3.0.0 PDFBox > > > After upgrading to `2.0.18`, the following code doesn't work for me anymore: > {code:java} > private void removeField() throws IOException { > PDAcroForm form = this.field.getAcroForm(); > List<PDField> allFields = form.getFields(); > PDAnnotationWidget widget = field.getWidgets().get(0); > List<PDAnnotation> allAnnotations = widget.getPage().getAnnotations(); > System.out.println("BEFORE: Fields size: " + allFields.size() + "; Field > to array: " + COSArrayList.converterToCOSArray(allFields)); > for(PDField field : allFields) { > if > (field.getFullyQualifiedName().equals(this.field.getFullyQualifiedName())) { > allFields.remove(field); > break; > } > } > System.out.println("AFTER: Fields size: " + allFields.size() + "; Field > to array: " + COSArrayList.converterToCOSArray(allFields)); > System.out.println("BEFORE: Annots size: " + allAnnotations.size() + "; > Annots to array: " + COSArrayList.converterToCOSArray(allAnnotations)); > for(PDAnnotation annotation : allAnnotations) { > if(annotation.getCOSObject().equals(widget.getCOSObject())) { > allAnnotations.remove(annotation); > break; > } > } > System.out.println("AFTER: Annots size: " + allAnnotations.size() + "; > Annots to array: " + COSArrayList.converterToCOSArray(allAnnotations)); > } > {code} > For whatever reason, the array in `COSArrayList` is not updating. The > internal `ArrayList` is updating, but not the internal `COSArray`. Here is > some output from above that might helpful after trying to remove a field from > a pdf with a single field. > {code:java} > // 2.0.17 > BEFORE: Fields size: 1; Field to array: COSArray{[COSObject{10, 0}]} > AFTER: Fields size: 0; Field to array: COSArray{[]} > BEFORE: Annots size: 1; Annots to array: COSArray{[COSObject{10, 0}]} > AFTER: Annots size: 0; Annots to array: COSArray{[]} > // 2.0.18 > BEFORE: Fields size: 1; Field to array: COSArray{[COSObject{10, 0}]} > AFTER: Fields size: 0; Field to array: COSArray{[COSObject{10, 0}]} > BEFORE: Annots size: 1; Annots to array: COSArray{[COSObject{10, 0}]} > AFTER: Annots size: 0; Annots to array: COSArray{[COSObject{10, 0}]} > {code} > I can definitely attach one of the PDFs I was working with if needed... But > this was happening with every PDF I tried it on, so I don't think it's > something special about the pdfs I was working with. -- This message was sent by Atlassian Jira (v8.3.4#803005) --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@pdfbox.apache.org For additional commands, e-mail: dev-h...@pdfbox.apache.org