Venkatesh
Venkatesh

Reputation: 311

how to add the checkbox into the Itext pdf table

am generating check-box inside Itext PDF Table but inside table check box is not generating its generating outside table.could please help me how to append that check box into PDF table.could you please help me out. Below is my code:

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

Upvotes: 0

Views: 8771

Answers (1)

Bruno Lowagie
Bruno Lowagie

Reputation: 77606

This is explained in the CheckboxCell example. That example was written in answer to Resizing a form field in iTextSharp, but it also answers your question.

Note that your question remained unanswered for so long because you used the [itextpdf] tag instead of [itext] or [itextsharp]. I only found this question by coincidence.

Upvotes: 2

Related Questions