Radio buttons on PDF resulting in error "Key path 'N' doesn't correspond appearance dictionary structure."

I have a very simple form, saved from Adobe Acrobat XI.

I am using Aspose for PDF for .NET version 8.3

I am using this code to access the form fields so I can fill in values. The code is in a loop where I send in field names.

var formField = pdfDocument.Form[fieldName] as Field;

This works fine if there are only text boxes and check boxes on the form. But when I add a set of radio buttons to the form, the code crashes on that line with the following error:

System.ArgumentException: Key path 'N' doesn't correspond appearance dictionary structure.
at Aspose.Pdf.InteractiveFeatures.Annotations.AppearanceDictionary.get_Item(Object key)
at Aspose.Pdf.InteractiveFeatures.Annotations.WidgetAnnotation.‹(String , Annotation )
at Aspose.Pdf.InteractiveFeatures.Annotations.WidgetAnnotation.‹(Annotation )
at Aspose.Pdf.InteractiveFeatures.Forms.Field.‹()
at Aspose.Pdf.InteractiveFeatures.Forms.Field.setValue(String value)
at Aspose.Pdf.InteractiveFeatures.Forms.Field.set_Value(String value)

Hi Glen,


Thanks for using our products.

Can you please share the source PDF file so that we can test the scenario at our end. We are sorry for this inconvenience.

This is the test PDF we have been using. If you request

var formField = pdfDocument.Form["FavoriteColor"] as Field;

then this line gives the error described above

formField.Value = "Red";

If I try

var formField = pdfDocument.Form["FavoriteColor"] as RadioButtonField;

then formField is null

My ultimate question is, what is the proper way in code to select one of a set of radio buttons?

Thanks.

Hi Glen,

Thanks for sharing the resource file.

I have tested the scenario using Aspose.Pdf for .NET 8.3.0 where I have used the following code snippet and I am unable to notice any problem. RadioButton value is properly being set.

For your reference, I have also attached the resultant PDF being generated over my end.

C#

Document pdfDocument = new Document("c:/pdftest/test2 (1).pdf");
var formField = pdfDocument.Form["FavoriteColor"] as RadioButtonField;
formField.Value = "Red";
pdfDocument.Save("c:/pdftest/RadioButtonSelected.pdf");

My apologies, this was summary code for a much more complicated process. I thought the issue was in the code I pasted. Here's where the problem is coming from. Apparently when you copy pages from one Document to another, something is happening to the radio button fields.

Document pdfDocument = new Document("c:/pdftest/test2 (1).pdf");

Document pdfDocument2 = new Document();

pdfDocument2.Pages.Add(pdfDocument.Pages);

var formField = pdfDocument2.Form["FavoriteColor"] as RadioButtonField;

formField.Value = "Red";
pdfDocument2.Save("c:/pdftest/RadioButtonSelected.pdf");

Hi Glen,


Thanks for sharing the details.

I have tested the scenario and I am able to
notice the same problem. For the sake of correction, I have logged this issue
as PDFNEWNET-35702 in our issue tracking system. We will
further look into the details of this problem and will keep you updated on the
status of correction. Please be patient and spare us little time. We are sorry
for this inconvenience.

The issues you have found earlier (filed as PDFNEWNET-35702) have been fixed in Aspose.Pdf for .NET 8.6.0.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.