java - how to distinguish between a checkbox field and a group of radio buttons -


when retrieve pdf field name using pdfbox

pdfield field = acroform.getfield('my_field'); 

i can't determine whether field single checkbox or group of radio buttons neither type of field nor field.getfieldtype(), because same in both cases.

i this

boolean ischeckbox = field.getwidgets().size() == 1; 

but not entirely reliable either, because radio group could contain 1 button.

instanceof can used determine type of field. if it's checkbox, type pdcheckbox. if field group of radio buttons type should pdradiocollection. code below trick on pdfbox version 1.8.10. appears class structure acroforms has changes on pdfbox 2.0.0.

if(field instanceof pdcheckbox){     type="checkbox"; }else if(field instanceof pdradiocollection){     type="radio"; } 

for version 2.0.0, according api documentation found here, pdbutton superclass of pdcheckbox , pdradiobutton. change code above, checking field instanceof pdcheckbox , field instanceof pdradiobutton.

note there bug report related issue. looks bug has since been fixed, make sure fix in release of pdfbox.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -