如果将keepTogether设置为true,为什么PdfPTable在段落中不可见?

时间:2019-09-04 11:17:27

标签: java itext openpdf

我正在使用 OpenPdf 1.3.8 itext 的叉子)和 openjdk 1.8.0_192

我正在尝试将表与两个文本(在上面的一个,在下面的一个文本)分组,以防止元素不适合页面剩余空间时分裂。

keepTogether 设置为true的情况下,

元素会添加到段落中。使用 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 可见。

0 个答案:

没有答案