首页 > 解决方案 > 使用 iText 将值设置为组合框

问题描述

我已经创建了PDF,我想使用iText为其中的组合框分配值。但我还没有找到任何解决方案。我尝试传递给. 但是方法只接受不那么错误。string arraysetValue()setValue()stringstring 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"});

标签: javaitextitext7

解决方案


 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"});

推荐阅读