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);
writer.addAnnotation(text.getComboField());
break;
case 4:
text.setChoices(LANGUAGES);
text.setOptions(TextField.EDIT);
writer.addAnnotation(text.getComboField());
break;
}
}
catch(IOException ioe) {
throw new ExceptionConverter(ioe);
}
catch(DocumentException de) {
throw new ExceptionConverter(de);
}
}这个是看api copy的代码 text.getComboField()报错 大神求指教或者哪位大神做过iText 列表框的给个例子 谢谢
//判断文档是否已经打开
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);
writer.addAnnotation(text.getComboField());
break;
case 4:
text.setChoices(LANGUAGES);
text.setOptions(TextField.EDIT);
writer.addAnnotation(text.getComboField());
break;
}
}
catch(IOException ioe) {
throw new ExceptionConverter(ioe);
}
catch(DocumentException de) {
throw new ExceptionConverter(de);
}
}这个是看api copy的代码 text.getComboField()报错 大神求指教或者哪位大神做过iText 列表框的给个例子 谢谢
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货