From 6482074d9bf20294fb294f29a2e29f1b480ca0de Mon Sep 17 00:00:00 2001 From: Leonid Peancovschi Date: Tue, 1 Dec 2020 09:42:07 +0000 Subject: [PATCH 1/2] Fix footer height calculation --- Source/Internal/Utils/PDFCalculations.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Internal/Utils/PDFCalculations.swift b/Source/Internal/Utils/PDFCalculations.swift index ade32abe..6d65de64 100644 --- a/Source/Internal/Utils/PDFCalculations.swift +++ b/Source/Internal/Utils/PDFCalculations.swift @@ -163,7 +163,7 @@ internal enum PDFCalculations { return pageLayout.height - layout.margin.top - - layout.heights.maxHeaderHeight() + - layout.heights.maxFooterHeight() } /** From 97d70179990f04bb4e0d5f415039417090fd0afe Mon Sep 17 00:00:00 2001 From: Leonid Peancovschi Date: Sat, 5 Dec 2020 10:08:26 +0000 Subject: [PATCH 2/2] Apply PR suggestions --- Source/Internal/Utils/PDFCalculations.swift | 33 +++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/Source/Internal/Utils/PDFCalculations.swift b/Source/Internal/Utils/PDFCalculations.swift index 6d65de64..d8b2e953 100644 --- a/Source/Internal/Utils/PDFCalculations.swift +++ b/Source/Internal/Utils/PDFCalculations.swift @@ -157,13 +157,42 @@ internal enum PDFCalculations { + layout.heights.maxHeaderHeight() } + /// Calculates the maximum offset from the top edge when the main content should break to the next page + /// + /// This method calculates the limit by the following formula: + /// + /// page height + /// - bottom margin + /// - footer height + /// - footer spacing (if footer exists) + /// - padding + /// ----------------------------------- + /// offset from top edge + /// + /// --- ┏━━━━━━━━━━┓ + /// ↑ ┃┌────────┐┃ + /// ↓ ┃│ Group │┃ + /// --> ┃└────────┘┃ + /// ┠┄┄┄┄┄┄┄┄┄┄┨ + /// ┃ spacing ┃ + /// ┠┄┄┄┄┄┄┄┄┄┄┨ + /// ┃ footer ┃ + /// ┠┄┄┄┄┄┄┄┄┄┄┨ + /// ┃ margin ┃ + /// ┗━━━━━━━━━━┛ + /// + /// - Parameter generator: Generator currently in use holding information about the document + /// - Returns: Offset from top edge in points internal static func calculateBottomMaximum(for generator: PDFGenerator) -> CGFloat { let layout = generator.layout let pageLayout = generator.document.layout + let footerHeight = layout.heights.maxFooterHeight() return pageLayout.height - - layout.margin.top - - layout.heights.maxFooterHeight() + - generator.currentPadding.bottom + - (footerHeight > 0 ? pageLayout.space.footer : 0) + - footerHeight + - layout.margin.bottom } /**