I created a pdf form with livecycle. a static pdf. now i want to fill some fields of this pdf. i have no problem with textbox but i have a problem with the dropdownlist. it's empty and i want to populate it.
PdfReader pdfReader = new PdfReader(pdfTemplate);
PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileStream(newFile, FileMode.Create));
AcroFields pdfFormFields = pdfStamper.AcroFields;
pdfFormFields.SetField("Dep", "44");
pdfFormFields.SetField("grp", "0");
pdfFormFields.SetListOption("gardien", new string[] { "English", "German", "French", "Spanish", "Dutch" }, new string[] { "EN", "DE", "开发者_如何学JAVAFR", "ES", "NL" });
the first two SetField have no problem, it works. but the SetListOption gives me this error :
The given key was not present in the dictionary
Can you help me plz, did I miss something ?
See this thread from a couple of years ago that talks about mixing PDF Fields with whatever Designer/LiveCycle creates that happens to look like form fields.
Basically iText (and thus iTextSharp) only support SetField
for fields created from with LiveCycle.
That said, the work-around is to use the field's keyname instead of its name. You can find the keyname by doing a foreach
on the pdfFormFields.Fields
property. You'll end up with something like topmostSubform[0].Page1[0].DropDownList1[0]
.
Once you've got that you can then do:
pdfFormFields.SetListOption("topmostSubform[0].Page1[0].DropDownList1[0]", new string[] { "English", "German", "French", "Spanish", "Dutch" }, new string[] { "EN", "DE", "FR", "ES", "NL" });
VERY IMPORTANT!! The values that you set here will work from with Adobe Reader/Acrobat but will be ignored by LiveCycle. If you're making the PDF from within LiveCycle but have no reason to ever open it again with that then you're find. If you're relying on XFA at all it might break, too.
精彩评论