Padding Applied on Each Page for Multi-Page Paragraphs
When a paragraph spans multiple pages, top/bottom padding is applied to the paragraph on each page, rather than just at the start/end of the paragraph. I don't think this should be the case.
Minimal code
from fpdf import FPDF
pdf = FPDF()
pdf.add_page()
pdf.set_font("Arial")
pad_bottom = 50
pdf.multi_cell(w = 0, text="Hello, this is a sample PDF!" * 300, padding=[0, 0, pad_bottom, 0])
pdf.output("sample.pdf")
Environment Please provide the following information:
- Operating System: Windows
-
- Python version: 3.12.2
-
-
fpdf2version used: 2.8.2
-
Hi @jasonfevangsafe
Thank you for the bug report 👍
I opened this PR with a potential solution: https://github.com/py-pdf/fpdf2/pull/1398
However I wonder if there was a good reason behind the actual behaviour...
I think the if self._perform_page_break_if_need_be(h + padding.bottom) check comes from https://github.com/py-pdf/fpdf2/pull/1048 made by @mjasperse last year.
If we remove the + padding.bottom from this check, as I did in PR https://github.com/py-pdf/fpdf2/pull/1398,
then the behaviour is the one you want @jasonfevangsafe:
there is no bottom padding inserted in case of a page break.
However this makes the situation non-symetrical: a top padding IS inserted in both parts of the split cell during this page break.
I'd be tempted to think that the current behaviour is fine, but I'd be happy to have your views on this @jasonfevangsafe, @andersonhc, @mjasperse 🙂
Hi, this behaviour was intentional. My original use-case required cells with a background color, but a filled padding margin was required at the bottom of the page otherwise the report was deemed to "look bad" by management.
If the padding is not desired across a page break, I wonder if padding is the correct feature to be using? Surely it would otherwise be a skip after the multicell?
Thank you for your feedback @mjasperse 👍
So far I would be tempted to label this as "a feature, not a bug" 🙂
My thinking is a multi-cell should have top and bottom padding applied once. I don't see why a page break should be an exception to this