简体   繁体   中英

How to set multiple option for PDListBox in PDFBox?

I am using PDFBox library to set the Values in PDF.

code block through I am trying to set values in ListBox

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

in result it shows only first value is selected from List<String> in PDF.
check result here:

How can I set multiple value selected in PDF?
PDFBox version : 2.0.6
Source pdf : https://www.dropbox.com/s/5cbicbuwu0kjwlq/2.pdf?dl=0

This is a bug in PDFBox up to 2.0.6, and has been fixed in issue PDFBOX-3828 . The fix will be in version 2.0.7, expected to be released in late summer / fall 2017. For those who can't wait, get a snapshot version here (at the bottom of that web page).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM