Issue with iText RadioCheckField when displayed on multiple pages

烈酒焚心 提交于 2019-12-07 18:56:52

问题


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.

来源:https://stackoverflow.com/questions/30895930/issue-with-itext-radiocheckfield-when-displayed-on-multiple-pages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!