0

多くのテーブルを持つ itext 5 を使用しています。各テーブルには、セルの高さが異なる多数の行があります。表の最初の行がページの残りの部分に収まらない場合、iText は表を分割し、ページの最後の行がヘッダー行で表示され、次のページの最初の行が 2 番目のヘッダー行で表示されます。

テーブルの最初の行がページの残りの部分に収まらない場合にのみ、新しいページに配置します。テーブルは、最初の行以外の任意の行で分割できる必要があります。setSplitRows、setSplitLate、および keepRowsTogether でこれを試しましたが、使用できません。

public class ProposalItextSplitRow {

public ProposalItextSplitRow() {
}

public static void main(String[] args) {
    try {
        String methodName = Thread.currentThread().getStackTrace()[2].getMethodName();
        Document document = new Document();
        document.setPageSize(PageSize.LETTER);
        document.setMargins(16, 14, 14, 14);
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("C:/Test.pdf"));
        document.open();
        document.setPageSize(PageSize.LETTER);
        document.setMargins(16, 14, 42, 38);

        for (int m = 1; m < 20; m++) {

            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);
            add(table, "Header Row normal " + m, BaseColor.LIGHT_GRAY);

            add(table, "Text Row 1 ", BaseColor.WHITE);
            add(table, "Text Row 2 ", BaseColor.WHITE);
            add(table, "Text Row 3 ", BaseColor.WHITE);

            addPadding(table);

            document.add(table);
        }

        document.close();
    } catch (Exception de) {
        de.printStackTrace();
    }
}

private static void add(PdfPTable table, String text, BaseColor color) {
    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(4f);
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setColspan(table.getNumberOfColumns());
    table.addCell(cell);
}

}

4

0 に答える 0