Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If the table spans across pages, the cells appear to be cut off in the middle. #41

Closed
walter-lee-querypie opened this issue Oct 29, 2024 · 2 comments
Assignees
Labels

Comments

@walter-lee-querypie
Copy link

walter-lee-querypie commented Oct 29, 2024

Thank you for creating a great library. However, while testing table creation, I discovered that in the case of long tables, the cells appear to be cut off in the middle when the page breaks. I would like to inquire if there is a way to resolve this issue.

Here is a simple test code to reproduce the issue.

        val landscapeA4 = PDRectangle(PDRectangle.A4.height, PDRectangle.A4.width)
        val pageSet = PLPageSet(landscapeA4).setMargin(40f)

        val r10 = FontSpec(PreloadFont.REGULAR, 10f)
        val r14b = FontSpec(PreloadFont.REGULAR, 10f)
        val aPadding = PaddingSpec(2f)

        val aTable = PLTable.createWithEvenlySizedColumns(4)
        aTable.setHeaderRowCount(1)
        aTable.setMargin(10f)

        // Add header row
        val aHeaderRow = aTable.addAndReturnRow(
            PLTableCell(PLText("No", r14b).setPadding(aPadding)),
            PLTableCell(PLText("B", r14b).setPadding(aPadding)),
            PLTableCell(PLText("C", r14b).setPadding(aPadding)),
            PLTableCell(PLText("Page Break", r14b).setPadding(aPadding)),
        )
        aHeaderRow.setFillColor(PLColor.GRAY)

        val row = listOf("column B", "column C", "1234567890\npage break test page break test page break test page break test page break test page break test page break test page break test")
        for (i in 0..32) {
            aTable.addRow(
                PLTableCell(PLText(i.toString(), r10).setPadding(aPadding)),
                PLTableCell(PLText(row[0], r10).setPadding(aPadding)),
                PLTableCell(PLText(row[1], r10).setPadding(aPadding)),
                PLTableCell(PLText(row[2], r10).setPadding(aPadding)),
            )
        }

        EPLTableGridType.FULL.applyGridToTable(aTable, BorderStyleSpec(PLColor.BLACK, 1f))
        pageSet.addElement(aTable)

        val pageLayout = PageLayoutPDF()
        pageLayout.addPageSet(pageSet)

        pageLayout.renderTo(File("page-break-sample.pdf"))

You can see that cell 7 is cut off in the middle as the page breaks.
image

The result I want is for row 7 to be written on the next page.
I would greatly appreciate it if you could provide a solution.

@phax phax self-assigned this Oct 29, 2024
@phax phax added bug question and removed bug labels Oct 29, 2024
@phax
Copy link
Owner

phax commented Oct 29, 2024

Hi @walter-chequer, thanks for reaching out to me.
Indeed there should be an easy way to remedy this issue.
By adding .setVertSplittable (false) to a PLText you can avoid the page break. See also #30

@walter-lee-querypie
Copy link
Author

@phax
The method you suggested works well.
Thank you for the quick response. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants