call .write_html in footer cause RecursionError
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
fpdf2version used:fpdf2 @ git+https://github.com/py-pdf/fpdf2@6f7a207d9c0b7e3f537b6a5f9f25e6ab0b693f8e
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).
@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
I opened #1247 to fix this.