We used to set all fields using FileFiled(string, string) method, however the radio buttons are no longer getting set. I’ve included code where I split out and was trying to find a solution, please advise:
public byte[] UpdateFieldData(NameValueCollection fields, byte[] bytes)
{
using (var pdfForm = new Form())
{
using (var ms = new MemoryStream(bytes))
{
pdfForm.BindPdf(ms);
foreach (string f in fields)
{
var value = fields[f];
switch (pdfForm.GetFieldType(f))
{
case FieldType.Radio:
try
{
if (!pdfForm.FillField(value, true))
{
_logger.LogTrace("{method} | FillField failed while updating form Field: '{f}'; Value: '{value}' in PDF", nameof(UpdateFieldData), f, value);
}
}
catch (Exception exception)
{
// Passive error
_logger.LogDebug(exception, "{method} | An error occurred when updating form Field: '{f}'; Value: '{value}' in PDF", nameof(UpdateFieldData), f, value);
}
break;
case FieldType.CheckBox:
case FieldType.PushButton:
case FieldType.MultiLineText:
case FieldType.Barcode:
case FieldType.InvalidNameOrType:
case FieldType.Signature:
case FieldType.Image:
case FieldType.Numeric:
case FieldType.DateTime:
case FieldType.Text:
case FieldType.ComboBox:
case FieldType.ListBox:
default:
try
{
if (!pdfForm.FillField(f, value))
{
_logger.LogTrace("{method} | FillField failed while updating form Field: '{f}'; Value: '{value}' in PDF", nameof(UpdateFieldData), f, value);
}
}
catch (Exception exception)
{
// Passive error
_logger.LogDebug(exception, "{method} | An error occurred when updating form Field: '{f}'; Value: '{value}' in PDF", nameof(UpdateFieldData), f, value);
}
break;
}
}
using (var finalStream = new MemoryStream())
{
pdfForm.Save(finalStream);
return finalStream.ToArray();
}
}
}
}