Hi rcastlespmg,
Thanks for your sharing.
After checking your PDF, I found that the values of the Radio button options are "1, 2, 3 ", not " 0 Days, 30 Days, 90 Days ". So it is impossible to set the state of the buttons according to the display value you mentioned. You need to change the corresponding values of the Radio button options. Please refer to below code to achieve your target.
- Code: Select all
string[] DisplayValues = { "0Days", "30Days", "90Days" };
String path = "changed.pdf";
PdfDocument doc = new PdfDocument("choice.pdf");
// fill form
var formWidget = doc.Form as PdfFormWidget;
int j = 0;
for (int i = 0; i < formWidget.FieldsWidget.List.Count; i++)
{
PdfField field = formWidget.FieldsWidget.List[i] as PdfField;
if (field is PdfRadioButtonListFieldWidget)
{
PdfRadioButtonListFieldWidget radioButton = field as PdfRadioButtonListFieldWidget;
foreach (PdfRadioButtonWidgetItem item in radioButton.WidgetWidgetItems)
{
item.Value = DisplayValues[j];
j++;
}
}
}
doc.SaveToFile(path);
PdfDocument document = new PdfDocument(path);
int index = 0;
var formWidget2 = document.Form as PdfFormWidget;
for (int i = 0; i < formWidget2.FieldsWidget.List.Count; i++)
{
PdfField field = formWidget2.FieldsWidget.List[i] as PdfField;
if (field is PdfRadioButtonListFieldWidget)
{
PdfRadioButtonListFieldWidget radioButton = field as PdfRadioButtonListFieldWidget;
foreach (PdfRadioButtonWidgetItem item in radioButton.WidgetWidgetItems)
{
if (item.Value == "30Days")
{
item.Checked = true;
index = radioButton.SelectedIndex;
}
}
}
}
document.SaveToFile("result.pdf");
Sincerely,
Anna
E-iceblue support team