rowspan 单元格中的文本在分页符处中断

Text in rowspan cell breaks on page break

我正在使用 iText 5.5.4 生成 pdf。

我有一堆行应该组合在一起,并有一个 rowspan 单元格来命名组。但是,在分页处,单词 "GRP" 被分成 "G" 和 "RP"。有没有办法让组牢不可破,如果它不能放在当前页面上,它将被绘制在下一页上?

我尝试了 keepRowsTogethersetBreakpoints,但没有得到一致的结果。

-------------------
| G |    row 1    |
| R |    row 2    |
| P |    row 3    |
-------------------


版面图片:

Document document = new Document(new Rectangle(300, 125));
PdfWriter.getInstance(document, new FileOutputStream(dest));
document.open();
document.add(new Paragraph("Table with setSplitLate(true):"));
PdfPTable table = new PdfPTable(2);
table.setWidths(new float[]{1,5});
table.setSpacingBefore(10);
PdfPCell cell = new PdfPCell();
cell.addElement(new Paragraph("G"));
cell.addElement(new Paragraph("R"));
cell.addElement(new Paragraph("O"));
cell.addElement(new Paragraph("U"));
cell.addElement(new Paragraph("P"));

//PdfPCell cell = new PdfPCell( new Phrase("GROUP"));
//cell.setNoWrap(true);
//cell.setRotation(90);
//cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
//cell.setHorizontalAlignment(Element.ALIGN_CENTER);

cell.setRowspan(5);
table.addCell(cell);
table.addCell("row 1");
table.addCell("row 2");
table.addCell("row 3");
table.addCell("row 4");
table.addCell("row 5");
document.add(table);
document.add(new Paragraph("Table with setSplitLate(false):"));
table.setSplitLate(false);
document.add(table);
document.close();

PDF Output from above code

当你在 Whosebug 上 post 提问时,你没有提供任何强制性代码(除非你对得到答案不感兴趣),我试着写了一个例子重现(不需要的)结果。

我没有成功。看我的 SplittingAndRowspan example:

document.add(new Paragraph("Table with setSplitLate(true):"));
PdfPTable table = new PdfPTable(2);
table.setSpacingBefore(10);
PdfPCell cell = new PdfPCell();
cell.addElement(new Paragraph("G"));
cell.addElement(new Paragraph("R"));
cell.addElement(new Paragraph("P"));
cell.setRowspan(3);
table.addCell(cell);
table.addCell("row 1");
table.addCell("row 2");
table.addCell("row 3");
document.add(table);

我并没有真正使用setSplitLate(true);,因为split late参数的默认值是true。结果如下所示:

由于包含 G R P 的单元格不适合页面,table 被转发到下一页(这正是您想要的)。

当然,当我使用setSplitLate(false)时不会发生这种情况:

document.add(new Paragraph("Table with setSplitLate(false):"));
table.setSplitLate(false);
document.add(table);

在这种情况下,包含G R P的单元格被拆分:

根据您问题中共享的稀缺信息,我假设您的代码中某处有行 table.setSplitLate(false);。如果是这样,请将其删除。如果没有,请分享您的代码。