gpt4 book ai didi

java - 如何在PDFBox中为PDListBox设置多个选项?

转载 作者:行者123 更新时间:2023-11-30 02:30:16 25 4
gpt4 key购买 nike

我正在使用 PDFBox 库来设置 PDF 中的值。

代码块通过我试图在列表框中设置值

public class App {
public static void main(String[] args) {
App app = new App();
app.test();
}
public void test(){
try {
InputStream resource = getClass().getResourceAsStream("/2.pdf");
PDDocument pdfDocument = PDDocument.load(resource);
PDDocumentCatalog docCatalog = pdfDocument.getDocumentCatalog();
PDAcroForm acroForm = docCatalog.getAcroForm();
PDListBox listBox = (PDListBox) acroForm.getField("multiple_listbox");
List<String> list = Arrays.asList("option 2", "option 1");
System.out.println("Set value in listBox: " + list);
listBox.setValue(list);
System.out.println("Get Value from list box: " + listBox.getValue());
pdfDocument.save("pdfupdate.pdf");
pdfDocument.close();
} catch (Exception e) {
e.printStackTrace();
}
}

结果显示仅从List<String>中选择了第一个值PDF 格式。
在这里检查结果:

如何设置在 PDF 中选择的多个值?
PDFBox版本:2.0.6
来源pdf:https://www.dropbox.com/s/5cbicbuwu0kjwlq/2.pdf?dl=0

最佳答案

这是 PDFBox 2.0.6 之前的错误,已在问题 PDFBOX-3828 中修复。 。该修复将在 2.0.7 版本中进行,预计将于 2017 年夏末/秋季发布。对于那些等不及的人,请获取 snapshot version在这里(在该网页的底部)。

关于java - 如何在PDFBox中为PDListBox设置多个选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44456172/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com