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

call .write_html in footer cause RecursionError #1222

Closed
socrateslee opened this issue Jul 10, 2024 · 4 comments · Fixed by #1247
Closed

call .write_html in footer cause RecursionError #1222

socrateslee opened this issue Jul 10, 2024 · 4 comments · Fixed by #1247

Comments

@socrateslee
Copy link

Describe the bug

Error details
Call .write_html in footer will result in a recursive call _perform_page_break -> add_page -> footer loop, therefore result in a RecursionError: maximum recursion depth exceeded error.

Minimal code

import fpdf

def render():
    class MyPDF(fpdf.FPDF):
            def footer(sub):
                sub.set_y(-15)
                sub.write_html("<p>this is a footer</p>")
    pdf = MyPDF(format='A4')
    pdf.add_page()
    pdf.write_html("<p>this is main content</p>")
    pdf.output('test.pdf')

render()

Environment
Please provide the following information:

  • Operating System: Windows with WSL2...
  • Python version: python 3.12
  • fpdf2 version used: fpdf2 @ git+https://github.com/py-pdf/fpdf2@6f7a207d9c0b7e3f537b6a5f9f25e6ab0b693f8e
@gmischler
Copy link
Collaborator

Thanks for reporting this, and welcome to fpdf2, @socrateslee !

That's quite an interesting bug you found there.
We should probably disable automatic page breaks while actually processing a page break (and when writing the last footer at the end of the document).

@Lucas-C
Copy link
Member

Lucas-C commented Aug 19, 2024

@allcontributors please add @socrateslee for bug

@socrateslee: would you like to submit a PR to fix this?
A good starting point would be to add unit test for this cas in test/html/test_html.py

Copy link

allcontributors bot commented Aug 19, 2024

@Lucas-C

I've put up a pull request to add @socrateslee! 🎉

@Lucas-C
Copy link
Member

Lucas-C commented Aug 20, 2024

I opened #1247 to fix this.

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

Successfully merging a pull request may close this issue.

3 participants