I'm setting the values of fields using PDF Sharp, and then saving the document. When I open the saved document in Adobe Acrobat, all of the fields are shown filled as they should be. Then I open the form in Chrome or Edge, and then only the text field values are present, and all of the RadioButtons are unset.
Here is a snippet of the code I'm using to set the field values.
Code:
public void SetFieldValue(string fieldName, string value)
{
var acroField = pdfsAcroForm.Fields[fieldName];
if (acroForm.fields.ContainsKey(fieldName))
{
string fieldType = acroForm.fields[fieldName].type;
if (fieldType == "Text")
{
acroForm.fields[fieldName].value = value;
acroField.Value = new PdfString(value);
}
else if (fieldType == "RadioButtons")
{
acroForm.fields[fieldName].value = value;
acroField.Value = new PdfName("/" + value);
}
else if (fieldType == "CheckBoxField")
{
acroForm.fields[fieldName].value = value;
PdfCheckBoxField checkbox = acroField as PdfCheckBoxField;
checkbox.CheckedName = value;
Debug.WriteLine("Setting a CheckBoxField to " + value);
}
else if (fieldType == "ComboBox")
{
acroForm.fields[fieldName].value = value;
PdfComboBoxField combobox = acroField as PdfComboBoxField;
combobox.Value = new PdfString("( )");
combobox.Value = new PdfString(value);
}
}
}
And here is the code I'm using when saving the form:
Code:
// Required to edit Fillable fields in the PDF
if (pdfsDocument.AcroForm.Elements.ContainsKey("/NeedAppearances") == false)
{
pdfsDocument.AcroForm.Elements.Add("/NeedAppearances", new PdfBoolean(true));
}
else
{
pdfsDocument.AcroForm.Elements["/NeedAppearances"] = new PdfBoolean(true);
}
pdfsDocument.Save(fpath);
pdfsDocument.Close();
Any ideas? I'm pretty confused and I can't think of anything else to try.