Reputation: 104
I am trying to use iText 7 to populate pdf forms programmatically. I use C# libraries. everything goes well so but choice fields. When a value is set for the field it becomes kinder highlighted in the resulting pdf. looks like this:
this does not happen to other types of fields. I am using PdfFormField.SetValue(string value)
function. I tried to cast type to PdfChoiceFormField
with the same result.
Any help?
PS here is the form.
PPS One more observation: I understand that iText is not changing background randomly (and not supposed to :) but here are values of the instance before and right after field.SetValue("California")
.
Upvotes: 1
Views: 746
Reputation: 76
To set the value of a choice field you need to use the SetListSelected
method like this:
string value = "hello world!";
if (ff is PdfChoiceFormField ch)
{
ch.SetListSelected(new[] { value });
}
else
{
ff.SetValue(value);
}
Of course value
should be one of the value allowed by the Choice field.
Upvotes: 1