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

showHeaderOnEveryPage #263

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions Source/Internal/Table/PDFTableObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ internal class PDFTableObject: PDFRenderObject {
let startPosition: CGPoint = cells.first?.frames.cell.origin ?? .zero
var nextPageCells: [PDFTableCalculatedCell] = cells
var pageEnd = CGPoint.null
var headerShift = true

repeat {
var pageStart = CGPoint.null
Expand All @@ -296,7 +297,9 @@ internal class PDFTableObject: PDFRenderObject {
var cellFrame = item.frames.cell
var contentFrame = item.frames.content
cellFrame.origin.y -= startPosition.y - minOffset
cellFrame.origin.y += table.margin
contentFrame.origin.y -= startPosition.y - minOffset
contentFrame.origin.y += table.margin

pageStart = pageStart == .null ? cellFrame.origin : pageStart
pageEnd = CGPoint(x: cellFrame.maxX, y: cellFrame.maxY) + CGPoint(x: table.margin, y: table.margin)
Expand Down Expand Up @@ -329,6 +332,15 @@ internal class PDFTableObject: PDFRenderObject {
}
minOffset += headerHeight
}
if !firstPage {
// shift the rest of the cells down by headerHeight
if headerShift {
nextPageCells = shiftCellsBy(cells: nextPageCells, shiftValue: headerHeight)
headerShift = false
}
//add table padding around cells
nextPageCells = shiftCellsBy(cells: nextPageCells, shiftValue: table.padding)
}

let filterResult = filterCellsOnPage(for: generator,
items: nextPageCells,
Expand Down Expand Up @@ -432,7 +444,6 @@ internal class PDFTableObject: PDFRenderObject {
if shouldSplitCellsOnPageBreak && cellFrame.minY < maxOffset {
result.cells.append(item)
}
// In any case, if the cell does not fit on the active page entirely, it must be repositioned for further pages
var nextPageCell = item
if shouldSplitCellsOnPageBreak {
nextPageCell.frames.cell.origin.y -= contentHeight
Expand All @@ -450,7 +461,22 @@ internal class PDFTableObject: PDFRenderObject {
}
return result
}


internal typealias ShiftedCells = ([PDFTableCalculatedCell])

internal func shiftCellsBy(cells: [PDFTableCalculatedCell], shiftValue: CGFloat) -> ShiftedCells {
var shiftedCells: [PDFTableCalculatedCell] = []

for cell in cells {
var shiftedCell = cell

shiftedCell.frames.cell.origin.y += shiftValue
shiftedCell.frames.content.origin.y += shiftValue
shiftedCells.append(shiftedCell)
}
return shiftedCells
}

internal func createSliceObject(frame: CGRect, elements: [PDFRenderObject], minOffset: CGFloat, maxOffset: CGFloat) -> PDFSlicedObject {
let sliceObject = PDFSlicedObject(children: elements, frame: frame)
if frame.maxY > maxOffset {
Expand Down
4 changes: 4 additions & 0 deletions Source/Internal/Utils/PDFCalculations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,21 @@ internal enum PDFCalculations {
return pageLayout.height
- layout.margin.top
- layout.heights.maxHeaderHeight()
- pageLayout.space.header
- layout.heights.content
- generator.currentPadding.bottom
- pageLayout.space.footer
- layout.heights.maxFooterHeight()
- layout.margin.bottom
}
}

internal static func calculateTopMinimum(for generator: PDFGenerator) -> CGFloat {
let layout = generator.layout
let pageLayout = generator.document.layout
return layout.margin.top
+ layout.heights.maxHeaderHeight()
+ pageLayout.space.header
}

/// Calculates the maximum offset from the top edge when the main content should break to the next page
Expand Down