You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Tilman Hausherr (Jira)" <ji...@apache.org> on 2020/02/16 13:47:00 UTC

[jira] [Comment Edited] (PDFBOX-4751) Removing field / annotation does not work

    [ https://issues.apache.org/jira/browse/PDFBOX-4751?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17023535#comment-17023535 ] 

Tilman Hausherr edited comment on PDFBOX-4751 at 2/16/20 1:46 PM:
------------------------------------------------------------------

targeting to 2.0.20 because that's obviously important.


was (Author: tilman):
targeting to 2.0.19 because that's obviously important.

> 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: 3.0.0 PDFBox, 2.0.20
>
>
> 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-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org