GlenKPeterson / PdfLayoutManager

Adds line-breaking, page-breaking, tables, and styles to PDFBox
45 stars 20 forks source link

How to fix the header in table when its goes to next page? #13

Open NayabHussain opened 7 years ago

NayabHussain commented 7 years ago

If the table extends to next page then how to attach the table header for that rows

GlenKPeterson commented 7 years ago

The answer to this is similar to your other question. Save your header row. If you get too close to the bottome of the page, make a new page with:

while (haveMoreRows) {
    Row builtRow = partBuilder.buildRow();

    if (builtRow.calcDimensions().y <= lp.yPageBottom()) {

        partBuilder.buildPart()
                .buildTable();
        lp.commit();
        // Make a new page
        lp = pageMgr.logicalPageStart();
        partBuilder = lp.tableBuilder(upperLeftCorner)
                .addCellWidths(someWidths)
                .textStyle(someStyle)
                .addPart(headerRowPart) // Saved header from earlier
                .partBuilder()
    }
    // Add your row
    partBuilder.addRow(builtRow)
}

Something like that. I think I mixed up a partBuilder and a rowBuilder or something. Hopefully it's close enough that you can get the idea.

See https://github.com/GlenKPeterson/PdfLayoutManager/blob/master/src/test/java/TestPdfLayoutMgr.java#L192