I\'m working on dynamically filling in the fields on a pdf document using ITextSharp. I\'d like to be able to determine the \"export value\" of the checkbox is from the cod
The best way I found to set a checkbox is:
void SetCB(AcroFields fields, string F)
{
try
{
fields.SetField(F, fields.GetFieldItem(F).GetValue(0).GetAsDict(PdfName.AP).GetAsDict(PdfName.N).Keys.Single().ToString().TrimStart('/'));
} catch { }
}
error: Sequence contains more than one element
e.g:
PdfReader reader = new PdfReader("c:\\qqq\\fl100Y2.pdf");// formFile);
using (PdfStamper stamper = new PdfStamper(reader, new FileStream("c:\\qqq\\fl100Ynew.pdf", FileMode.Create)))
{
AcroFields fields = stamper.AcroFields;
bool set = fields.SetFieldProperty("FillText156", "textsize", 10.0f, null);
SetCB(fields, "CheckBox24");
SetCB(fields, "CheckBox24by");
fields.SetField("FillText156", "John Doe");
// flatten form fields and close document
stamper.FormFlattening = true;
stamper.Close();
}