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

Free Support Forum - aspose.com

Check RadioButtonOptionField

Hello,


Is it possible to check the RadioButtonOption using Aspose.Pdf?
Please see the attached PDF with the group of RadioButtonOption.
I would like to check the second radio button with option “Opt2”.

Best regards, Evgeniy

Hello,


Can someone assist me here? Does Aspose.Pdf have the corresponding API?

Just a remark:
For the most of other field types Aspose.Pdf API is clear.

TextBoxField:
field.setValue(“some text”);

ChechboxField:
field.setChecked(true);

ChoiceField:
field.setSelected(0);

but for RadioButtonOptionField I could not find any API to select the option in code.

Best regards, Evgeniy

Hi Evgeniy,


Thanks for contacting support and sorry for the delayed response.

In order to accomplish your requirements, please try using following code snippet. For your reference, I have also attached the resultant PDF generated over my end.

[Java]

//Open a document <o:p></o:p>

com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document("c:/pdftest/RadioCheckBox_AcroForm.pdf");

//Get a field

com.aspose.pdf.RadioButtonField radioBoxField = (com.aspose.pdf.RadioButtonField)pdfDocument.getForm().get("OrdinaryRadio");

//Select second radio button option

radioBoxField.setSelected(2);

//Save the updated document

pdfDocument.save("c:/pdftest/RadioCheckBox_AcroForm_RadioSelected_output.pdf");

Hi Nayyer,


Thanks a lot for your support.
But how could you find field name “OrdinaryRadio”? I used method pdfDocument.getForm().getFields() and the array does not include such RadioButtonField.

Best regards, Evgeniy

Hi Evgeniy,


Thanks for your feedback. It is good to know that provided code worked for you. Please check following code while using Aspose.Pdf for Java 9.5.2, getFields() method is retrieving properly the form fields. If you still face any issue then please share some more details so we will look into it and guide you accordingly.

Document pdf = new Document(“RadioCheckBox_AcroForm.pdf”);<o:p></o:p>

Field[] fields = pdf.getForm().getFields();

for (int i = 0; i < fields1.length; i++) {

System.out.println("Form field: " + fields[i].getFullName());


Please feel free to contact us for any further assistance.


Best Regards,

Hi Tilal,


OK, this works but different field types are returned for the same field using two methods

1. form.get(“OrdinaryRadio”) => RadioButtonField
2. form.getFields()[1] ==> RadioButtonOptionField
but it is the field with the same name “OrdinaryRadio” (check is form.getFields()[1].getFullName() => “OrdinaryRadio”).

Looks like that for method form.getFields() the incorrect field type is set for RadioButtonField.

Best regards, Evgeniy

Hi Evgeniy,


Thanks for your inquiry. Please note get() method returns field object of the passed fieldname. Whereas getField() object gets lowest level of field, RadioButtonOptionfield in case of RadioButtonField, you may get other properties of the field for example FullName, Value etc. Please share more details if there is some difference in your point and my understanding.

get(String fieldname)

Searches field by field name and return Field Object. Returns null if field was not found.

getFields()

Method get fields in lowest level of hierarchical form.

We are sorry for the inconvenience caused.

Best Regards,

Hi Tilal,


Thanks for your answers.
I recommend you to write such description to the documentation of the methods because it was really very confusing to get different instances.

Best regards, Evgeniy

Hi Evgeniy,


We are sorry for the confusion. We are in process of updating the API documentation of Aspose.Pdf for Java in document section. Meanwhile you may refer javadoc folder in download folder of Aspose.Pdf for Java from your machine.

Best Regards,