Issue with iText RadioCheckField when displayed on

2019-05-22 16:23发布

I am creating a PDF in which the AcroForm fields will be rendered inside a table. I am having issue with RadioButtons when they spread across two pages. I have modified example shown on this link http://itextpdf.com/sandbox/acroforms/CreateRadioInTable . Only the craetePdf method from above example is modified.

public void createPdf(String dest) throws IOException, DocumentException {
    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document,new FileOutputStream(dest));
    document.open();
    PdfFormField radiogroup = PdfFormField.createRadioButton(writer, true);
    radiogroup.setFieldName("Language");
    PdfPTable table = new PdfPTable(2);
    PdfPCell cell;
    for (int i = 0; i < 25; i++) {
        cell = new PdfPCell(new Phrase("Question " + i));
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("Answer " + i));
        table.addCell(cell);
    }
    for (int i = 0; i <25; i++) {
        cell = new PdfPCell(new Phrase("Radio: " + i));
        table.addCell(cell);
        cell = new PdfPCell();
        cell.setCellEvent(new MyCellField(radiogroup, "radiogroup" + i));
        table.addCell(cell);
    }
    document.add(table);
    writer.addAnnotation(radiogroup);
    document.close();
}

A PdfPTable is created with 50 rows. When the radiobutton gets split in between two pages, it gets messed up in formatting. Please check this link for output PDF from above code. http://www.docdroid.net/13smb/checkbox-in-cell.pdf.html

By looking at the PDF it appears that all the radiobuttons gets rendered on page 2 because the table ends on page 2. I have tried to set page number with setPageInPlace(pageNumber) while creating RadioCheckFields as following, but it did not work.

RadioCheckField radio = new RadioCheckField(writer, rectangle, null, value);
PdfFormField field = radio.getRadioField();
field.setPlaceInPage(placeInPage);

Is there a way to fix this issue? I have tried to use PdfStamper, but was not able to fix this problem. Any help will be greatly appreciated.

0条回答
登录 后发表回答