We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

RadioButtonOptionField

Hi I am trying to edit a pdf form using the java aspose-pdf library. I want to select option for a RadioButtonOptionField field in my document, but i am unable to find any documentation on how to check/uncheck the radio button. Can you please provide some example code for that.

@MEDHOK

Thanks for contacting support.

You may use RadioButtonField.setSeclected() method, in order to check any of the options field. However, we have tested the scenario in our environment by following code snippet and it seemed that the feature is not working. Therefore, we have logged an issue as PDFJAVA-37793 in our issue tracking system. We will investigate this behavior of the API and keep you posted with the status of its correction. Please be patient and spare us little time.

Document doc = new Document();
Page page = doc.getPages().add();
Table table = new Table();
table.setColumnWidths("120 120");
page.getParagraphs().add(table);
Row r1 = table.getRows().add();
Cell c1 = r1.getCells().add();
Cell c2 = r1.getCells().add();

RadioButtonField rf = new RadioButtonField(page);
rf.setPartialName("radio");
doc.getForm().add(rf, 1);

RadioButtonOptionField opt1 = new RadioButtonOptionField();
RadioButtonOptionField opt2 = new RadioButtonOptionField();

opt1.setOptionName("Item1");
opt2.setOptionName("Item2");

opt1.setWidth(15);
opt1.setHeight(15);
opt2.setWidth(15);
opt2.setHeight(15);

rf.add(opt1);
rf.add(opt2);

opt1.setBorder(new Border(opt1));
opt1.getBorder().setWidth(1);
opt1.getBorder().setStyle(BorderStyle.Solid);
opt1.getCharacteristics().setBorder(Color.BLACK);
opt1.getDefaultAppearance().setTextColor(Color.RED);
opt1.setCaption(new TextFragment("Item1"));
opt2.setBorder(new Border(opt2));
opt2.getBorder().setWidth(1);
opt2.getBorder().setStyle(BorderStyle.Solid);
opt2.getCharacteristics().setBorder(Color.BLACK);
opt2.getDefaultAppearance().setTextColor(Color.RED);
opt2.setCaption(new TextFragment("Item2"));
c1.getParagraphs().add(opt1);
c2.getParagraphs().add(opt2);
		
rf.setSelected(2);
		
doc.save(dataDir + "RadioButtonField.pdf");

We are sorry for the inconvenience.