我已经创建 PDF ,我想使用 iText 为其中的 comboBox 指定值。但我还没有找到任何解决方案。我尝试将string array
传递给setValue()
。但setValue()
方法仅接受string
而不是string array
,因此会收到错误。
PdfReader reader = new PdfReader(src);
PdfDocument pdf = new PdfDocument(reader, new PdfWriter(dest));
PdfAcroForm form = PdfAcroForm.getAcroForm(pdf, true);
Map<String, PdfFormField> fields = form.getFormFields();
fields.get("Name").setValue(emp.getEmployeeName()).setBackgroundColor(Color.ORANGE);
fields.get("Combobox").setValue([]string{"en", "hi"});
答案 0 :(得分:0)
String dest = "D:/filename.pdf";
// get original pdf template
PdfReader reader = new PdfReader(src);
PdfStamper filledOutForm = new PdfStamper(reader, new FileOutputStream(dest));
AcroFields fields = filledOutForm.getAcroFields();
// available options in dropdown can be specified by using following line
fields.setListOption("Country Combo Box",new String[]{"India", "USA", "Pakistan", "Bangladesh"}, new String[]{"India", "USA", "Pakistan", "Bangladesh"});
// selected option out of available
fields.setListSelection("Country Combo Box", new String[]{"India"});