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

another fix for showHeaderOnEveryPage #264

Merged
merged 79 commits into from
Mar 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
f756e5a
Updated docs for
Jun 24, 2020
bfee891
Updated docs for
Jun 24, 2020
d17548a
Updated docs for
Jun 24, 2020
bf9b18a
Updated docs for
Jun 25, 2020
17dc161
Updated docs for
Jun 26, 2020
ecba679
Updated docs for
Jun 28, 2020
ba6a78f
Added landing page with redirection
Jul 1, 2020
e2013e4
Updated docs for
Jul 1, 2020
34a39cb
Updated docs for
Jul 2, 2020
8ac72eb
Updated docs for
Jul 9, 2020
739fbc2
Updated docs for
Jul 16, 2020
2fc8b88
Updated docs for
Jul 16, 2020
f0c9a6b
Updated docs for
Jul 16, 2020
91e64b4
Updated docs for
Jul 23, 2020
99d5598
Updated docs for
Jul 30, 2020
c84be40
Updated docs for
Aug 6, 2020
ed1213b
Updated docs for
Aug 13, 2020
e2dd206
Updated docs for
Aug 20, 2020
c3244c1
Updated docs for
Aug 27, 2020
69551cc
Updated docs for
Sep 3, 2020
b629679
Updated docs for
Sep 10, 2020
537b656
Updated docs for
Sep 17, 2020
b0e7404
Merge branch 'master' into gh-pages
Sep 23, 2020
7fed85c
Updated docs for
Sep 23, 2020
930481f
Updated docs for
Sep 26, 2020
8f97c81
Merge branch 'master' into gh-pages
Sep 26, 2020
2b34637
Updated docs for
Sep 26, 2020
ce5a417
Updated docs for
Oct 1, 2020
28c9f01
Updated docs for
Oct 8, 2020
1069ff3
Merge branch 'master' into gh-pages
Oct 12, 2020
f98bb2e
Updated docs for
Oct 12, 2020
28701d5
Updated docs for
Oct 15, 2020
fc70bf9
Updated docs for
Oct 22, 2020
a6fc3a1
Updated docs for
Oct 29, 2020
dfd307a
Updated docs for
Nov 5, 2020
be59409
Updated docs for
Nov 12, 2020
c0ce4b9
Updated docs for
Nov 19, 2020
f9e3c28
Merge branch 'master' into gh-pages
Nov 21, 2020
f96b001
Updated docs for
Nov 21, 2020
74a4fee
Merge branch 'master' into gh-pages
Nov 21, 2020
910f475
Updated docs for
Nov 21, 2020
437b823
Merge branch 'master' into gh-pages
Nov 21, 2020
13011a4
Updated docs for
Nov 21, 2020
3122574
Updated docs for
Nov 21, 2020
b26dba4
Updated docs for
Nov 26, 2020
adb6e74
Updated docs for
Dec 3, 2020
533810a
Merge branch 'master' into gh-pages
Dec 5, 2020
ac6bc3b
Updated docs for
Dec 5, 2020
8ab0b1f
Updated docs for
Dec 10, 2020
84c14bc
Updated docs for
Dec 17, 2020
6fd3f53
Updated docs for
Dec 24, 2020
9ad0e78
Updated docs for
Dec 31, 2020
e733307
Merge branch 'master' into gh-pages
Jan 6, 2021
0bb8ecd
Updated docs for
Jan 6, 2021
a788b3d
Merge branch 'master' into gh-pages
Jan 7, 2021
55fac1c
Updated docs for
Jan 7, 2021
2c6d6aa
Updated docs for
Jan 7, 2021
53453df
Update PDFCalculations.swift
Sgkhour Aug 23, 2020
50d8d47
Update PDFTableObject.swift
Sgkhour Aug 23, 2020
736f9ba
Updated docs for
Jan 14, 2021
c1afb59
Updated docs for
Jan 21, 2021
c3e12ed
Update PDFTableObject.swift
Sgkhour Jan 23, 2021
85245e8
Updated docs for
Jan 28, 2021
c90a89e
Updated docs for
Feb 4, 2021
8f10b3f
Updated docs for
Feb 11, 2021
fa144dd
Updated docs for
Feb 18, 2021
652ba1e
Update PDFTableObjectSpec.swift
Sgkhour Feb 20, 2021
ae52122
Update PDFTableObjectSpec.swift
Sgkhour Feb 20, 2021
f888982
Update PDFTableObjectSpec.swift
Sgkhour Feb 20, 2021
283259b
Update PDFTableObject.swift
Sgkhour Feb 21, 2021
3bde7f8
Update PDFTableObjectSpec.swift
Sgkhour Feb 22, 2021
342bc97
Updated docs for
Feb 25, 2021
c0bc151
Fixed test cases
Feb 27, 2021
b0daf0a
Added page layout spacer explaination to README
Feb 27, 2021
554ccf5
Fixed copy-paste error in docs
Feb 27, 2021
917c4ed
Merge branch 'gh-pages'
Sgkhour Feb 28, 2021
b35163a
Merge branch '222-show-header-height-fixes'
Sgkhour Feb 28, 2021
e2d145b
Update PDFListItemObject_Spec.swift
Sgkhour Mar 1, 2021
dbaa0e1
remove the docs directory
Sgkhour Mar 2, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion Documentation/Usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ All values are in dots and are rendered using 72 DPI (dots per inch), as this is

You can also used the predefined formats. For details please refer to the source file [PDFPageFormat.swift](https://github.com/techprimate/TPPDF/blob/master/Source/PDFPageFormat.swift)

Keep in mind that the `space.header` is only applied, if there is at least one element in a header container.
The same applies to the `space.footer` for footer containers and elements.

If you need your page in landscape format, use the `landscapeSize` variable.

![Layout](../resources/layout.png)
Expand Down Expand Up @@ -820,4 +823,4 @@ If you want to enable a debug overlay, set the flag `debug` of the `PDFGenerator
let document: PDFDocument
let generator = PDFDocumentGenerator(document: document)
generator.debug = true
```
```
20 changes: 0 additions & 20 deletions Source/Internal/Graphics/PDFContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,18 @@ public class PDFContext {

internal func beginPDFPage(_ pageInfo: CFDictionary?) {
// Do not create page immediately, instead invoke it as soon as necessary
print("beginPDFPage")
delayedCommands.append(.beginPDFPage(pageConfig: pageInfo))
currentPageContainsDrawnContent = false
hasActivePage = true
}

internal func endPDFPage() {
print("endPDFPage")
applyDelayedCommands()
cgContext.endPDFPage()
hasActivePage = false
}

internal func closePDF() {
print("closePDFPage")
applyDelayedCommands()
cgContext.closePDF()
hasActivePage = false
Expand All @@ -61,33 +58,28 @@ public class PDFContext {
// MARK: - Translation

internal func translateBy(x: CGFloat, y: CGFloat) {
print("translateBy")
delayedCommands.append(.translateBy(x: x, y: y))
}

internal func scaleBy(x: CGFloat, y: CGFloat) {
print("scaleBy")
delayedCommands.append(.scaleBy(x: x, y: y))
}

// MARK: - Drawing

internal func drawPath(using mode: CGPathDrawingMode) {
print("drawPath")
applyDelayedCommands()
cgContext.drawPath(using: mode)
currentPageContainsDrawnContent = true
}

internal func drawPDFPage(_ page: CGPDFPage) {
print("drawPDFPage")
applyDelayedCommands()
cgContext.drawPDFPage(page)
currentPageContainsDrawnContent = true
}

internal func draw(image: CGImage, in frame: CGRect, flipped: Bool) {
print("draw(image:)")
applyDelayedCommands()
cgContext.draw(image: image, in: frame, flipped: flipped)
currentPageContainsDrawnContent = true
Expand All @@ -96,7 +88,6 @@ public class PDFContext {
// MARK: - Colors

internal func setFillColor(_ color: CGColor) {
print("setFillColor")
applyDelayedCommands()
cgContext.setFillColor(color)
currentPageContainsDrawnContent = true
Expand All @@ -105,42 +96,36 @@ public class PDFContext {
// MARK: - Paths

internal func beginPath() {
print("beginPath")
applyDelayedCommands()
cgContext.beginPath()
currentPageContainsDrawnContent = true
}

internal func addPath(_ path: CGPath) {
print("addPath")
applyDelayedCommands()
cgContext.addPath(path)
currentPageContainsDrawnContent = true
}

internal func setLineDash(phase: CGFloat, lengths: [CGFloat]) {
print("setLineDash")
applyDelayedCommands()
cgContext.setLineDash(phase: phase, lengths: lengths)
currentPageContainsDrawnContent = true
}

internal func setLineCap(_ cap: CGLineCap) {
print("setLineCap")
applyDelayedCommands()
cgContext.setLineCap(cap)
currentPageContainsDrawnContent = true
}

internal func setLineWidth(_ width: CGFloat) {
print("setLineWidth")
applyDelayedCommands()
cgContext.setLineWidth(width)
currentPageContainsDrawnContent = true
}

internal func setStrokeColor(_ color: CGColor) {
print("setStrokeColor")
applyDelayedCommands()
cgContext.setStrokeColor(color)
currentPageContainsDrawnContent = true
Expand All @@ -149,13 +134,11 @@ public class PDFContext {
// MARK: - State

internal func saveGState() {
print("saveGState")
applyDelayedCommands()
cgContext.saveGState()
}

internal func restoreGState() {
print("restoreGState")
applyDelayedCommands()
cgContext.restoreGState()
}
Expand All @@ -172,7 +155,6 @@ public class PDFContext {
}

internal func draw(ctFrame frameRef: CTFrame) {
print("draw(ctFrame:)")
applyDelayedCommands()
CTFrameDraw(frameRef, cgContext)
currentPageContainsDrawnContent = true
Expand All @@ -181,7 +163,6 @@ public class PDFContext {
// MARK: - Masking

internal func clip() {
print("clip")
applyDelayedCommands()
cgContext.clip()
currentPageContainsDrawnContent = true
Expand All @@ -190,7 +171,6 @@ public class PDFContext {
// MARK: - Metadata

internal func setURL(_ url: CFURL, for rect: CGRect) {
print("setURL")
applyDelayedCommands()
cgContext.setURL(url, for: rect)
currentPageContainsDrawnContent = true
Expand Down
39 changes: 33 additions & 6 deletions Source/Internal/Table/PDFTableObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -284,19 +284,25 @@ internal class PDFTableObject: PDFRenderObject {
let startPosition: CGPoint = cells.first?.frames.cell.origin ?? .zero
var nextPageCells: [PDFTableCalculatedCell] = cells
var pageEnd = CGPoint.null
var headerShift = table.showHeadersOnEveryPage


repeat {
var pageStart = CGPoint.null

// Calculate top page inset
var minOffset = PDFCalculations.calculateTopMinimum(for: generator)
// Calculate bottom page maximum limit
let maxOffset = PDFCalculations.calculateBottomMaximum(for: generator)

if !firstPage, let headerCells = headerCells {
for item in headerCells {
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,11 +335,18 @@ 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.margin)
}

let filterResult = filterCellsOnPage(for: generator,
items: nextPageCells,
minOffset: minOffset,
maxOffset: maxOffset,
let filterResult = filterCellsOnPage(for: generator, items: nextPageCells,
minOffset: minOffset, maxOffset: maxOffset,
shouldSplitCellsOnPageBreak: table.shouldSplitCellsOnPageBreak)
let onPageCells = filterResult.cells
nextPageCells = filterResult.remainder
Expand Down Expand Up @@ -432,7 +445,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 +462,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