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

Tilman Hausherr edited comment on PDFBOX-5225 at 6/26/21, 1:48 PM:
-------------------------------------------------------------------

My thought was to change the second part of that method to this:
{code}

        Set<COSDictionary> widgetDictionarySet = new HashSet<>();
        for (PDField field : fields)
        {
            List<PDAnnotationWidget> widgets = field.getWidgets();
            for (PDAnnotationWidget widget : widgets)
            {
                widgetDictionarySet.add(widget.getCOSObject());
            }
        }

        for (PDPage page : document.getPages())
        {
            for (PDAnnotation annotation : page.getAnnotations())
            {
                if (widgetDictionarySet.contains(annotation.getCOSObject()))
                {
                    fillPagesAnnotationMap(pagesAnnotationsMap, page, 
(PDAnnotationWidget) annotation);
                }
            }
        }
{code}
It seems to work but now the annotations are direct objects, and the file can't 
be opened with Adobe Reader.

Update: it also fails a flatten test. This is getting tricky.


was (Author: tilman):
My thought was to change the second part of that method to this:
{code}

        Set<COSDictionary> widgetDictionarySet = new HashSet<>();
        for (PDField field : fields)
        {
            List<PDAnnotationWidget> widgets = field.getWidgets();
            for (PDAnnotationWidget widget : widgets)
            {
                widgetDictionarySet.add(widget.getCOSObject());
            }
        }

        for (PDPage page : document.getPages())
        {
            for (PDAnnotation annotation : page.getAnnotations())
            {
                if (widgetDictionarySet.contains(annotation.getCOSObject()))
                {
                    fillPagesAnnotationMap(pagesAnnotationsMap, page, 
(PDAnnotationWidget) annotation);
                }
            }
        }
{code}
It seems to work but now the annotations are direct objects, and the file can't 
be opened with Adobe Reader.

> Flattening removes all annotations when widget annotation has no page
> ---------------------------------------------------------------------
>
>                 Key: PDFBOX-5225
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-5225
>             Project: PDFBox
>          Issue Type: Bug
>          Components: AcroForm
>    Affects Versions: 2.0.24
>            Reporter: Tilman Hausherr
>            Priority: Major
>         Attachments: SourceFailure.pdf
>
>
> {code}
>         PDAcroForm acroForm = doc.getDocumentCatalog().getAcroForm();
>         List<PDField> list = new ArrayList<>();
>         list.add(acroForm.getField("VN_NAME"));
>         acroForm.flatten(list, true); 
> {code}
> The code from buildPagesWidgetsMap that is run when there are widgets with 
> missing page references does not consider the field list. So all widgets end 
> up in the map instead of only those we care about.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to