I am renaming PDF form fields to unique values found in my local database. It basically maps the PDF form field to a field in my table, so I can dynamically load data to it at run-time.
Hi Richard,
Hi Richard,
Thanks for sharing the input file and sample code snippet. I am afraid that you are using old Aspose.Pdf.Facades approach is going to be obsolete soon. We are not resolving issue(s) related to the old approach. We strongly recommend using the new Document Object Model (DOM) approach.
By using the DOM approach you can rename the RadioButtonOptionField and also set their values programmatically. You do not need to split the Group just to rename the Options so that your other code can read the specified name and select it. Please check the following code snippet to rename the option fields, save the document, and then set option values respectively. I hope this will help.
// Loaddocument
Document pdfDocument = new Document("name.pdf");
foreach(var field in pdfDocument.Form.Fields)
{
if(field is RadioButtonOptionField)
{
RadioButtonOptionField rbf = (RadioButtonOptionField)field;
if (rbf.OptionName.Equals("Male"))
rbf.Name = "q123_M";
if (rbf.OptionName.Equals("Female"))
rbf.Name = "q123_F";
}
}
// Save Document
pdfDocument.Save("Updated_name.pdf");
// Load Document Again with updated option names
pdfDocument = new Document("Updated_name.pdf");
foreach (var field in pdfDocument.Form.Fields)
{
if (field is RadioButtonOptionField)
{
RadioButtonOptionField rbf = (RadioButtonOptionField)field;
// Set the value of "Male" option
if (rbf.Name == "q123_M")
rbf.ActiveState = "Male";
}
}
// Save document with updated values
pdfDocument.Save("name_malechecked.pdf");
I have also attached the output file(s). If you still face further issues please feel free to contact us.
Best Regards,
Hi,
Hi Richard,
Thanks for sharing more details. I tried to change the name of RadioButtonField in the input file (name.pdf) and was able to achieve that. Please check the following code snippet to change the name of RadioButtonField. I am also attaching the output generated by the below code.
Document pdfDocument = new Document("name.pdf");
foreach (var field in pdfDocument.Form)
{
if (field is RadioButtonField)
{
RadioButtonField rbf = (RadioButtonField)field;
rbf.Name = "Updated_Name";
}
}
pdfDocument.Save("name_out.pdf");
Moreover I am still investigating on modifying radio buttons so that they can work as check boxes. As there is already grouping in the Document it will take some time. I will update you and share my findings about this perspective. Please have patience.
Best Regards,