java - 使用 iText 将值设置为组合框
问题描述
我已经创建了PDF,我想使用iText为其中的组合框分配值。但我还没有找到任何解决方案。我尝试传递给. 但是方法只接受不那么错误。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"});
解决方案
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"});
推荐阅读
- java - 对从 1 到 n 的值求和一系列 n^n 且没有溢出?只需要答案的最后一位数字
- c++ - 了解为什么会出现不需要的 cout 语句迭代
- c - 输出字符的 C 程序生成整数
- python - 为什么我的 OpenCV 的 GUI 元素(轨迹栏、窗口)有不同的设计?
- c# - 需要澄清单例+游戏对象
- python - 如何使用beautifulsoup和python获取span标签中的文本
- vb.net - 我是否可以创建计划以在 Azure 上的 Web 应用程序中运行函数,如果可能,是否可以传递参数?
- css - 垂直动画文本旋转
- arrays - 按数组中的值对 JSON 进行排序 (node.js)
- android - AndroidX PreferenceFragmentCompat 找不到片段的 id id/内容的视图