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

New Page Generated #326

Open
tazmancoder opened this issue Apr 9, 2023 · 2 comments
Open

New Page Generated #326

tazmancoder opened this issue Apr 9, 2023 · 2 comments

Comments

@tazmancoder
Copy link

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

@tazmancoder
Copy link
Author

What I’m trying to figure out is how much info can fit on a page. Is there a way to know this info?

@philprime
Copy link
Member

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants