TPPDF
TPPDF copied to clipboard
New Page Generated
I'm using this library in my project. Is there a way of being informed when a new page is generated without calling createNewPage(). I would like to be able to let the library generate the PDF and every time a section changes I can update it and if a new page is generated place the name of the section at the top adding "continued" much like bank statement do.
Thanks Taz
What I’m trying to figure out is how much info can fit on a page. Is there a way to know this info?
The PDFGenerator
has a property delegate: PDFGeneratorDelegate
, where PDFGeneratorDelegate
combines multiple generator delegate protocols.
Therefore my approach would be adding a PDFGeneratorLayoutDelegate
with the necessary delegation functions (e.g. generatorWillEndPage
, generatorDidEndPage
, generatorWillBeginPage
, generatorDidBeginPage
) and call them here:
https://github.com/techprimate/TPPDF/blob/main/Source/Internal/Layout/PDFPageBreakObject.swift#L73
Untested example what it could look like:
override internal func draw(generator: PDFGenerator, container: PDFContainer, in context: PDFContext) throws {
if !stayOnSamePage {
generator.delegate?.generatorWillEndPage()
PDFContextGraphics.gendPDFPage(in: context)
generator.delegate?.generatorDidEndPage()
generator.delegate?.generatorWillBeginPage()
PDFContextGraphics.beginPDFPage(in: context, for: generator.document.layout.bounds)
generator.delegate?.generatorDidBeginPage()
// if there is a background color set, fill the page with it
if let color = generator.document.background.color {
PDFGraphics.drawRect(in: context, rect: generator.document.layout.bounds, outline: .none, fill: color)
}
generator.drawDebugPageOverlay(in: context)
}
applyAttributes(in: context)
}
Pull-requests are welcome!