iText 创建列表框报
空指针public void addListBox() throws Exception{
//判断文档是否已经打开
if(!document.isOpen()) {
document.open();
}
writer = PdfWriter.getInstance(document, new FileOutputStream(filePath));
writer.setViewerPreferences(PdfWriter.PageModeUseOutlines);
Rectangle rect = new Rectangle(300, 300, 300, 300);
int cf =1;
TextField text = new TextField(writer, rect,String.format("choice_%s", cf));
String[] LANGUAGES ={"English","French","German"};
String[] EXPORTVALUES = { "EN", "DE", "FR", "ES", "NL" };
try {
switch(cf) {
case 1:
text.setChoices(LANGUAGES);
text.setChoiceExports(EXPORTVALUES);
text.setChoiceSelection(2);
writer.addAnnotation(text.getListField());
break;
case 2:
text.setChoices(LANGUAGES);
text.setBorderColor(BaseColor.GREEN);
text.setBorderStyle(PdfBorderDictionary.STYLE_DASHED);
text.setOptions(TextField.MULTISELECT);
ArrayList<Integer> selections = new ArrayList<Integer>();
selections.add(0);
selections.add(2);
text.setChoiceSelections(selections);
PdfFormField field = text.getListField();
writer.addAnnotation(field);
break;
case 3:
text.setBorderColor(BaseColor.RED);
text.setBackgroundColor(BaseColor.GRAY);
text.setChoices(LANGUAGES);
text.setChoiceExports(EXPORTVALUES);
text.setChoiceSelection(4);