我正在使用 java 处理 itext 5。我有带有动态行的多个表的页面。在某些情况下,表格的最后一行被拆分为具有以下标题的下一页。我正在使用setHeaderRows()和setSkipFirstHeader()管理下一页的继续。最后一行有足够的空间可以放在前面的页面上。我想将最后一行放在同一页而不是下一页。
例如,在第 1 页上,最后一行被拆分为下一页的第一行。相反,我想将该行放在第 1 页中,因此请保存一个额外的页面,其中包含所有空白。
我尝试使用setExtendLastRow(),但它不起作用。有谁知道如何解决这个问题。我附上了一个工作示例代码。
public class ProposalItextSplitLastRow {
 public static void main(String[] args) {
    try {
        Document document = new Document();
        document.setPageSize(PageSize.LETTER);
        document.setMargins(16, 14, 14, 14);
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("C:/SplitLastRow.pdf"));
        document.open();
        document.setPageSize(PageSize.LETTER);
        document.setMargins(16, 14, 42, 38);
        for (int m = 1; m < 20; m++) {
            int row = 0;
            PdfPTable table = new PdfPTable(1);
            table.setSpacingAfter(0);
            table.setSpacingBefore(0);
            table.setWidthPercentage(100);
            table.setHeaderRows(1);
            table.setSkipFirstHeader(true);
            add(table, "Header Row continued " + m, BaseColor.LIGHT_GRAY, row++);
            add(table, "Header Row normal " + m, BaseColor.LIGHT_GRAY, row++);
            add(table, "Text Row 1 ", BaseColor.WHITE, row++);
            add(table, "Text Row 2 ", BaseColor.WHITE, row++);
            add(table, "Text Row 3 ", BaseColor.WHITE, row++);
            addPadding(table);
            document.add(table);
        }
        document.close();
    } catch (Exception de) {
        de.printStackTrace();
    }
}
private static void add(PdfPTable table, String text, BaseColor color, int row) {
    PdfPCell pdfCellHeader = new PdfPCell();
    pdfCellHeader.setBackgroundColor(color);
    pdfCellHeader.addElement(new Paragraph(new Phrase(text)));
    table.addCell(pdfCellHeader);
}
private static void addPadding(PdfPTable table) {
    PdfPCell cell = new PdfPCell();
    cell.setFixedHeight(2f);
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setColspan(table.getNumberOfColumns());
    table.addCell(cell);
}
}