TPPDF icon indicating copy to clipboard operation
TPPDF copied to clipboard

Table header repeats in new page.

Open vivek350 opened this issue 1 year ago • 0 comments

I am building a pdf with dynamic data. I have multiple tables. The problem I'm having is when the document has only space for one row, which is the header, the header repeats twice in first page and second page again. This happens because I used testTable.showHeadersOnEveryPage = true.

I want the headers repeating in every page. All I want is to find a way to check if the first 2 rows of the table fit in the remaining space of the page, if not I can move the table to the next page.

What did you do?

testArray.insert(["Eaglewoods buzzy accurate eardrop", "Number of absent bleachers", "Accurate Source"], at: 0)
let testTable = PDFTable(rows: testArray.count, columns: 3)
testTable.padding = 10
testTable.widths = [0.3, 0.2, 0.5]
let lineStyle = PDFLineStyle(type: .full, color: UIColor.black, width: 1)
let borders = PDFTableCellBorders(left: lineStyle, top: lineStyle, right: lineStyle, bottom: lineStyle)
let font = UIFont.systemFont(ofSize: 10)
testTable.style = PDFTableStyle(columnHeaderCount: 1, footerCount: testArray.count - 1, outline: PDFLineStyle(type: .full, color: UIColor.black, width: 1), columnHeaderStyle: PDFTableCellStyle(borders: borders, font: UIFont.boldSystemFont(ofSize: 12)), footerStyle: PDFTableCellStyle(borders: borders, font: font))
testTable.content = testArray
testTable.rows.allRowsAlignment = [.center, .center, .center]
testTable.showHeadersOnEveryPage = true

What did you expect to happen?

ℹ I have a table beginning almost at the end of the page. I have no way of knowing the position since it would always be dynamic. The problem occurs only when there's space for header in the page. The header repeats in the new page. If I can calculate the space left in the page, I can move the table to next page.

What happened instead?

Image 4-11-23 at 11 26 AM

TPPDF Environment

TPPDF version: ℹ 2.4.1 Xcode version: ℹ 14.1 Swift version: ℹ 5

Demo Code / Project

I cannot provide the whole document since it's not my personal project. If the data provided is not enough I can create a sample app and provide the link here. Thanks

vivek350 avatar Apr 11 '23 15:04 vivek350