Free Support Forum -

Problem using getButtonOptionValues function


I am trying to use getButtonOptionValues to get a list of radion button values in pdf files, but failed. As I undestand, I need to refer the radio button objects with the full name.

Here is How I called the function:
HashMap radioValues2 =

It throws an exception.

What is the correct way to call this function?

Please use the attached pdf file as input.


Hi Ying,

Please access the button as shown below:

HashMap radioValues2 = form.getButtonOptionValues(“form1[0].subForm[0].wr_allow_work_on_holidays[0]”);

Moreover, if you want to get names of all the fields in the PDF file, you can use the following code snippet:

String[] fieldnames = form.getFieldsNames();

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

I hope this helps. If you have any further questions or concerns, please do let us know.

Hi ,

Thanks for reply.

I tried your suggestions but the HashMap is empty.

I also tried with the getFieldNames(0 function and retrieved the field names as:
Just as you suggested.

However, the HashMap is not filled. It sounds like a bug in getButtonOptionValues for me.


Hi Ying,

I have used the following code snippet with the file you shared earliest and it returns the radio button values at my end:

Form form = new Form(“work_request.pdf”, “output.pdf”);

HashMap radioValues2 = form.getButtonOptionValues(“form1[0].subForm


Iterator iterator = radioValues2.keySet().iterator();

while (iterator.hasNext())


String key = (String);



//String[] fieldnames = form.getFieldsNames();

//for (int i = 0; i < fieldnames.length; i++)


// System.out.println(fieldnames[i]);



I have tested this issue with the latest version of the component - Aspose.Pdf.Kit for Java 2.6.0. If you're not using the latest version then please download it and use the above code with this version.

Moreover, if you're having this problem with some file other than the one shared already then please share the new file as well.

We're sorry for the inconvenience and looking forward to help you out.


Thanks for the suggestions. Yes, I am using a newer version of pdf file and the function getButtonOptionValues works - I need to refer the element with index [0], as I understand now.

However, when I tried to set the field’s radio button value using setField function, it failed.

Then I tried to find out what values are contained in each field as following

form.getFieldValue(“form1[0].wrForm[0].wr_allow_work_on_holidays[0]”);"= “OFF” //?? Is there should be a value here since it is a group?

form.getFieldValue(“form1[0].wrForm[0].wr_allow_work_on_holidays[0].#field[1]”);"= null

form.getFieldValue(“form1[0].wrForm[0].wr_allow_work_on_holidays[0].#field[0]”);"= null

Can you advise how to set the “Yes” radio button in Java?


p.s I attached the latest pdf for your references.


I just found out a solution for the problem: I have need to specify a default value in the radio button group in pdf otherwise, it will consider the radio button group in not active. Not sure if it is as designed, but it is good enough for me to go forward.

Thanks for you help!

Hi Ying,

In order to fill a field you need to use setField method. This method provides different overloads and one of these overloads is used to set the value of a radio button; you can use the overload on this link to set a radio button value:

public void setField(java.lang.String fieldName,

int index)

throws java.lang.Exception

In this overload, you need to pass the index of the value you need to set as selected.

I hope this helps. If you need any further assistance, please do let us know.