So I create a radio group using this PdfFormField.createRadioButton() then calling the setFieldName().
However, the PdfAnnotation does not show any keys that stores the field name. I looked at the other dictionaries inside the PdfAnnotation but could not find any.
reader.getAcroFields().getFields().keySet() does list the field names of the form fields but I wish to ask if there is any way via PdfAnnotation?
I tried to put a custom PdfName inside the radio group object but it does not show up in the PdfAnnotation's dictionary.
You are confusing the concept of an annotation (link annotation, file attachment annotation, widget annotation,...) and a form field (text field, choice field, button field, signature field).
In iText 5, annotations are dealt with in a class named
PdfAnnotation
; form fields are dealt with in a class namedPdfFormField
. You are trying to do something that is specific for aPdfFormField
using the classPdfAnnotation
. That's wrong.I understand the root of the confusion: every visible form field corresponds with at least one widget annotation. Most of the visible form fields correspond with exactly one widget annotation. That's why we made a design choice in iText 5 to have
PdfFormField
extendsPdfAnnotation
.This design choice is in line with the PDF specification where it says that field dictionaries of fields that correspond with a single widget annotation may be merged into a single PDF dictionary.
In practice, you will find PDF dictionaries in a PDF that combine entries typical for a widget annotation dictionary and a field dictionary. (That also explains why there's a
getMerged()
method in iText: that method gets you the merged dictionary objects.)I hope this already explains part of your problem. You seem to have another problem too, but I don't understand what you want to do. Please clarify using references to ISO-32000-1 so that people can understand which technical feature you are trying to implement.