form.Fields contains the single RadioButtonOptionFields instead of the superior RadioButtonFields

Hi,
we want to read all form fields from different PDF documents. The list is then saved in our program and linked with data. The data should then be written into the fields. For RadioButtonFileds Doc.Form.Fields contains the RadioButtonOptionFields instead of the superior RadioButtonField. Is there a way to change this? In addition, the RadioButtonOptionFields do not have the same or a consecutive TabOrder. They are therefore displayed in different places in a sorted list.

Best regards
Markus

@MarkusPlesoft

Thank you for contacting support.

Would you please share a sample document along with SSCCE code so that we may try to reproduce and investigate it in our environment. Before sharing requested data, please ensure using Aspose.PDF for .NET 19.11.

Hello,

i have the same question. I would like to get a RadioButtonField of a pdf document.
Calling the method pdfDocument.getForm().getFields() will return RadioButtonOptionFields. I would have expect RadioButtonField too.
At the moment i am using the parent method of the RadioButtonOptionField to get its RadioButtonField.
RadioButtonField radioButtonField = (RadioButtonField) radioButtonOption.getParent();
Is there another way to get the RadioButtonField?

Example for PDF with a single RadioButton is attached.
RadioButton.pdf (116.8 KB)

Kind regards
Matthias

@curmas

Please try using following code snippet:

Document pdfDocument = new Document(dataDir + "radiobutton.pdf");
Field[] fields = pdfDocument.getForm().getFields();
System.out.println(fields.length);
for(Field field : fields){
 if(field instanceof RadioButtonOptionField){
   // do stuff
 }
}

Hi,

thanks for answer. I want to get the RadioButtonField, not the RadioButtonOptionField. Is there any way to get the RadioButtonField?

Kind regards
Matthias

@curmas

Please modify above-shared code snippet as following:

if(field instanceof RadioButtonField){
 // do stuff
 RadioButtonField f = (RadioButtonField)field; 
 // do stuff
}

Hi,
method pdfDocument.getForm().getFields() does not return any RadioButtonField. This is the problem!
In given example file “RadioButton.pdf” method getFields() returns three fields - all fields are instances of RadioButtonOptionField.

My question: Is there any other way to get the RadioButtonField?
Thanks.

Kind regards
Matthias

@curmas

Would you kindly share a bit more details on what you want to achieve after getting RadioButtonField? Do you intend to modify it or read some properties? We will further investigate the scenario accordingly and share our feedback with you.

Hi,
i want to set the value of the RadioButtonField. In given example there is an RadioButtonField with three options “Item1”, “Item2” and “Item3”. For example i want to set value “Item2” for RadioButtonField.
At the moment i use the following code to achieve this:

  	if (field instanceof RadioButtonOptionField)
  	{
  		RadioButtonOptionField radioButtonOption = (RadioButtonOptionField) field;
  		RadioButtonField radioButtonField = (RadioButtonField) radioButtonOption.getParent();

  		if (radioButtonField != null)
  		{
  			radioButtonField.setValue("Item2");
  		}
  	}

My question: Is there any better way to set or get the value of a RadioButtonField?
Thanks.

Kind regards
Matthias

@curmas

Thanks for explaining the case further.

We have logged an investigation ticket as PDFJAVA-39701 in our issue tracking system. We will look into its details and inform you as soon as it is resolved and your requirements can be achieved. Please be patient and spare us some time.

We are sorry for the inconvenience.

@curmas

We have further investigated the earlier logged ticket and we recommend using following code snippet:

Document doc = new Document(dataDir+"radiobutton.pdf");
Form form = doc.getForm();
for (WidgetAnnotation wa : form){
 if (wa instanceof  RadioButtonField) {
  ((RadioButtonField) wa).setValue("Item2");
 }
}
doc.save(dataDir+"radiobutton_out.pdf");

Thanks.

Kind regards
Matthias

1 Like