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

Maruan Sahyoun commented on PDFBOX-2873:
----------------------------------------

Let me add some background first. An interactive form field in a PDF consists 
of two entries - the field and the annotation. Both are dictionaries which can 
be combined in one as the dictionary keys are unique between annotations and 
fields. The key /Ff belongs to the field dictionary, the key /F belongs to the 
annotation dictionary. As the same field might be represented multiple times 
visually a field might have multiple annotation assigned to it. So above code 
only works if the field has a single annotation.

To get the annotation(s) associated with the field you can call 
{{field.getWidgets()}} wich gives you a list of {{PDAnnotationWidget}}. With 
these you can use methods such as {{setHidden}}.

So in fact you don't set the annotation flags on top of the field. You set them 
for the annotation. 

> Make bitfields public in PDField like in PDAnnotation
> -----------------------------------------------------
>
>                 Key: PDFBOX-2873
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-2873
>             Project: PDFBox
>          Issue Type: Improvement
>          Components: PDModel
>    Affects Versions: 2.0.0
>            Reporter: Roberto Nibali
>            Priority: Minor
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> I need to set COSName.FF and COSName.F dictionary entries to amend a broken 
> fields clone from one PDF to another. Here is part of the code to illustrate 
> what I'm trying to achieve:
>                 String fieldToHideName = "01.024";
>                 String fieldToShowName = "01.0251";
>                 PDField fieldToHide = 
> tplDoc.getDocumentCatalog().getAcroForm().getField(fieldToHideName);
>                 PDField fieldToShow = 
> tplDoc.getDocumentCatalog().getAcroForm().getField(fieldToShowName);
>                 fieldToHide.getCOSObject().setFlag(COSName.F, 
> PDAnnotation.FLAG_HIDDEN, true);
>                 fieldToShow.getCOSObject().setFlag(COSName.F, 
> PDAnnotation.FLAG_INVISIBLE, false);
>                 fieldToShow.getCOSObject().setFlag(COSName.FF, 
> PDFields.FLAG_READ_ONLY, true);
> The last one is not possible because the PDField's static flags are private 
> instead of public. I know there are methods to call, but I believe in this 
> case the resulting code is easier to read and more straight-forward to write. 
> After all we're talking about setting flags. For some reason the 
> PDAnnotation's static flags are public. 



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

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

Reply via email to