How to select a value from a combo box using itextsharp in c#
I have a fill-able pdf whi开发者_如何学运维ch has a combo box and the values in it.How can i select a single value programmatically using c# and itextSharp?
You just set the value like any other form field. You can either set an option by value or by name. If you have a combo box called cbo1
with these three options:
-------------------
|Name | Value |
-------------------
|Option 1 | 1 |
|Option 2 | 2 |
|Option 3 | 3 |
-------------------
You can use this to set the value:
//Open the existing PDF
PdfReader pdfReader = new PdfReader("Test.pdf");
//Create the output PDF
PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileStream("Test-Output.pdf", FileMode.Create));
//Get access to the PDF's form fields
AcroFields pdfFormFields = pdfStamper.AcroFields;
//Select by option's name
pdfFormFields.SetField("cbo1", "Option 3");
//- OR -
//Select by option's value
pdfFormFields.SetField("cbo1", "3");
pdfStamper.FormFlattening = false;
pdfStamper.Close();
pdfReader.Close();
精彩评论