【发布时间】:2014-01-04 09:49:49
【问题描述】:
正在生成 Itext PDF 表中的复选框,但表内复选框未生成其生成的外部表。请帮助我如何将该复选框附加到 PDF 表中。请您帮帮我。 以下是我的代码:
Class A{
public void createFourColumnBody() throws DocumentException, FileNotFoundException {
com.itextpdf.text.Document document = new com.itextpdf.text.Document(PageSize.A4);
com.itextpdf.text.pdf.PdfWriter writer1 = PdfWriter.getInstance(document, new FileOutputStream("D:\\PDF_Java.pdf", false));
document.open();
float[] widths = new float[]{30f, 30f};
com.itextpdf.text.pdf.PdfPTable table = new com.itextpdf.text.pdf.PdfPTable(widths);
table.setWidthPercentage(100);
table.setHorizontalAlignment(Element.ALIGN_LEFT);
PdfFormField checkboxGroupField = PdfFormField.createCheckBox(writer1);
PdfPCell cell = table.getDefaultCell();
PdfPCell cell12;
cell = new PdfPCell(new Paragraph("checkbox3"));
table.addCell(cell);
cell12 = new PdfPCell(table.getDefaultCell());
cell12.setCellEvent(new CellField(writer1, checkboxGroupField, true));
table.addCell(cell12);
writer1.addAnnotation(checkboxGroupField);
document.add(table);
document.close();
}
public static void main(String[] args) throws DocumentException, FileNotFoundException {
A a1 = new A();
a1.createFourColumnBody();
}
}
【问题讨论】: