Reputation: 13
To manipulate radiobuttons with iText, I know how to get field names and using AcroFields.getAppearanceStates to get their possible values. But I just couldn't find any method to determine which option was selected. Is it a missing feature in iText?
Upvotes: 1
Views: 507
Reputation: 9816
Yeah radiobuttons can be confusing - but that is more due to their definition in the PDF spec and not necessarily due to iText. Actually the appearance state (in the childs) should indicate which value has been selected. (the (/V) value of the parent should also contain the selected value). Which possible values do exist (Yes1, Yes2 and Yes3) you can find out by iterating over the children and extracting their appearance dictionaries. There might be a shortcut if an (optional) options array (e.g. /Opt[(Yes1)(Yes2)(Yes3)]) does exists.
So lets make an example:
//The Parent Object aka radio button group
4 0 obj
<</FT/Btn/Ff 49154/Kids[97 0 R 102 0 R 107 0 R]/T(RadiobuttonGroup)/V/Yes2>>
endobj
//child 1
97 0 obj
<</AP<</N<</Yes1 98 0 R/Off 99 0 R>>>>/AS/Off/BS<</S/I/W 1>>/F 4/MK<</BC[0.0]/BG[1.0]/CA(l)>>/P 19 0 R/Parent 4 0 R/Rect[502 770 515 781]/Subtype/Widget/Type/Annot>>
endobj
//child 2
102 0 obj
<</AP<</N<</Yes2 98 0 R/Off 99 0 R>>>>/AS/Ja2/BS<</S/I/W 1>>/F 4/MK<</BC[0.0]/BG[1.0]/CA(l)>>/P 19 0 R/Parent 4 0 R/Rect[522 770 535 782]/Subtype/Widget/Type/Annot>>
endobj
//child 3
107 0 obj
<</AP<</N<</Yes3 98 0 R/Off 99 0 R>>>>/AS/Off/BS<</S/I/W 1>>/F 4/MK<</BC[0.0]/BG[1.0]/CA(l)>>/P 19 0 R/Parent 4 0 R/Rect[540 770 553 782]/Subtype/Widget/Type/Annot>>
endobj
As you can see: the actual value which is selected (a) in the AS of child2 and (b) in the value (/V) of the parent.
Upvotes: 1