I am using ITextSharp to fill in my pdf, but I don't know how to check a checkbox.
I have different cases :
- I have just 1 box. If the value I get is "true", I check it, otherwise not.
- I have 2 boxes, "Yes" and "No". If the value is true, I check Yes, otherwise, I check No.
- I have multiple choice. For example, I have "Title", with possible values "Mr", "Mrs" and "Miss". I want to check the box corresponding to the value I get (I will get "Mr", or "Mrs", or "Miss".
Actually, this is what I do :
if (Output.AcroFields.Fields.ContainsKey(m.Item1))
{
// Boolean or not (have to treat differently)
if (Input.Data[m.Item2] is Boolean)
{
Output.AcroFields.SetField(m.Item1, (bool)Input.Data[m.Item2] ? "On" : "Off"); // I've tried "True", "On", "true"
}
else
{
Output.AcroFields.SetField(m.Item1, Input.Data[m.Item2].ToString());
}
}
But checkboxes are never ticked. Text fields work, but not these 3 cases. Any idea ?