OpenPdf 1.3.8 ( itext のフォーク)とopenjdk 1.8.0_192を使用しています。
ページの残りの空きスペースに要素が収まらない場合に要素が分割されるのを防ぐために、テーブルを 2 つのテキスト (テーブルの上に 1 つ、テーブルの下に 1 つ) でグループ化しようとしています。
keepTogetherを true に設定して、要素をParagraphに追加します。setKeepTogether(true)を使用すると、奇妙な動作に気付きました。
setKeepTogether(true)が呼び出された場合、テーブルは表示されず、他の要素は次のようになります:
setKeepTogether(false) の場合 - すべてが期待どおりに機能します。
これが私のコード例です:
public static void main(String[] args) throws DocumentException, FileNotFoundException {
Document document = new Document();
PdfWriter pdfWriter = PdfWriter.getInstance(document, new FileOutputStream(DEST));
document.open();
PdfPTable table = new PdfPTable(2);
table.addCell("Lorem");
table.addCell("ipsum");
table.addCell("dolor");
table.addCell("sit");
Paragraph mainParagraph = new Paragraph();
Paragraph paragraph1 = new Paragraph("Text above table");
Paragraph paragraph2 = new Paragraph("Text below table");
mainParagraph.add(paragraph1);
mainParagraph.add(table);
mainParagraph.add(paragraph2);
// if keeptogether is true, table is not visible
mainParagraph.setKeepTogether(true);
document.add(mainParagraph);
document.close();}
何が起こっているかの手がかりはありますか?
コードはitext 5.5.13でもテストされています。どちらの場合もitextを使用すると、テーブルが表示されます。