【问题标题】:how to add the checkbox into the Itext pdf table如何将复选框添加到 Itext pdf 表中
【发布时间】: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();
    }
    }

【问题讨论】:

    标签: java pdf itext


    【解决方案1】:

    这在CheckboxCell 示例中进行了说明。该示例是为回答 Resizing a form field in iTextSharp 而编写的,但它也回答了您的问题。

    请注意,由于您使用的是 [itextpdf] 标签而不是 [itext] 或 [itextsharp],因此您的问题一直没有得到解答。偶然发现这个问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-03
      • 1970-01-01
      • 2014-02-27
      • 2018-03-31
      • 2022-07-31
      • 1970-01-01
      • 2011-12-31
      • 1970-01-01
      相关资源
      最近更新 更多