AcroForm フィールドがテーブル内にレンダリングされる PDF を作成しています。RadioButtons が 2 つのページにまたがると問題が発生します。このリンクhttp://itextpdf.com/sandbox/acroforms/CreateRadioInTableに示されている例を変更しました。上記の例の craetePdf メソッドのみが変更されています。
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();
}
PdfPTable は 50 行で作成されます。ラジオボタンが 2 つのページに分割されると、フォーマットがめちゃくちゃになります。上記のコードから PDF を出力するには、このリンクを確認してください。http://www.docdroid.net/13smb/checkbox-in-cell.pdf.html
PDF を見ると、テーブルがページ 2 で終了するため、すべてのラジオボタンがページ 2 にレンダリングされるように見えます。次のように RadioCheckFields を作成しているときに setPageInPlace(pageNumber) でページ番号を設定しようとしましたが、うまくいきませんでした。
RadioCheckField radio = new RadioCheckField(writer, rectangle, null, value);
PdfFormField field = radio.getRadioField();
field.setPlaceInPage(placeInPage);
この問題を解決する方法はありますか? PdfStamper を使用しようとしましたが、この問題を解決できませんでした。どんな助けでも大歓迎です。