From 7a0a2099ea6bf674600ed8278aafa7fe76c2c990 Mon Sep 17 00:00:00 2001 From: Lucas Cimon <925560+Lucas-C@users.noreply.github.com> Date: Fri, 14 Mar 2025 16:09:57 +0100 Subject: [PATCH] Fix: do not insert bottom padding in cells produced by multi_cell() when a page break occurs in them --- CHANGELOG.md | 1 + fpdf/fpdf.py | 2 +- .../multi_cell_with_padding_and_page_break.pdf | Bin 0 -> 1795 bytes test/text/test_multi_cell.py | 10 ++++++++++ 4 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 test/text/multi_cell_with_padding_and_page_break.pdf diff --git a/CHANGELOG.md b/CHANGELOG.md index 69f40564d..8d4f5533a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ This can also be enabled programmatically with `warnings.simplefilter('default', ### Fixed * [`FPDF.write_html()`](https://py-pdf.github.io/fpdf2/fpdf/fpdf.html#fpdf.fpdf.FPDF.write_html): Fixed rendering of content following `` tags; now correctly resets emphasis style post `` tag: hyperlink styling contained within the tag authority. - [Issue #1311](https://github.com/py-pdf/fpdf2/issues/1311) * [FPDF.footer()](https://py-pdf.github.io/fpdf2/fpdf/fpdf.html#fpdf.fpdf.FPDF.footer) does not "leak" its text style to the [table of contents](https://py-pdf.github.io/fpdf2/DocumentOutlineAndTableOfContents.html#table-of-contents) anymore +* do not insert bottom padding in cells produced by [`FPDF.multi_cell()`](https://py-pdf.github.io/fpdf2/fpdf/fpdf.html#fpdf.fpdf.FPDF.multi_cell) when a page break occurs in them - [issue #1395](https://github.com/py-pdf/fpdf2/issues/1395) ## [2.8.2] - 2024-12-16 ### Added diff --git a/fpdf/fpdf.py b/fpdf/fpdf.py index 5e9df0e65..c91924006 100644 --- a/fpdf/fpdf.py +++ b/fpdf/fpdf.py @@ -4146,7 +4146,7 @@ def multi_cell( page_break_triggered = False for text_line_index, text_line in enumerate(text_lines): - if self._perform_page_break_if_need_be(h + padding.bottom): + if self._perform_page_break_if_need_be(h): page_break_triggered = True self.y += padding.top diff --git a/test/text/multi_cell_with_padding_and_page_break.pdf b/test/text/multi_cell_with_padding_and_page_break.pdf new file mode 100644 index 0000000000000000000000000000000000000000..4f31a87b27777be3f50c37e5440fbb52088bc7db GIT binary patch literal 1795 zcmcIleNYr-7@w?6H@~Ku=KPp?8^1t|-FLaY+dWUFBHfPey0#sNJT(W2CPDE?;xIEHtsZ4D z5dB^+CQwc7e6HkI0GTQxv*h(>i$kys)F7P^CuUyZy;4?`8#T}ecMugMDl*Ux**JI~ zevL3Vku3Rr0+In6O{qGM;!{l{d{&QFK|UO-msgMl36dKTq#cP_%6gEXV^k|y@gY8& z2$VNo`gY0VCQU(G;>zAju?>dS*7M8arqwRtrB@uUZrx{TxHUav%C>+3bj@EI?6}*u zF}AD6`kDU1;g1(o8_HfBxOiooJ+&*wcXy$^>(s<{^RWw5ULY^;#Db)*b(?>AzHD4x z;GgSPy5}FyKHB-yuIwW>yWSnRY@4&UG{-vktMX;X5)82uf41G)+F2QFx=|ThQTnIG z^*-DY2sBh60hW2BKDlTb)x@l)x_RSDxP7Pag ziYI1irsJ=OGpl-L2%FuSt`ebY?wM7SgQ4yT!WA}riY`9h1e>jep=LImjx=xn2%F3K zs;Tv>(h5T>*zkrd&B5J`OJ6G6nXe-YylaWeHP0Q%ja}cDZ(qB+?rA!3xBu#2k9~a- zJgIiraNdV|P3_Z2(ah3t6X+h@1l%K2ysypxK>wev&v9`>K`EARX zp6@v0xq_Kv`>vI>PZnFn{?$gAh1WOkIonogGcMbn!)`m@KFd(>?71cFwduj|u0Cz^ zj*3w8ZEf>2i-behJXPZt2~3}Mg)107fVYy0(1Clux5U}*{2i*;dh+%CP2bEqNRQ6B zJ}O5^yo{_k?|@v4yl)}JBk%;7EaHLjh*^MK=@Ct$?1=ybndZ+>21P@a4j373l_6>p z)hWGS1eM%qB&`srew}#oNQX}n(vSjNB-S%PE=K|E-+Td&@oH`12Vw_3`eal zAl}Cyg%x%LMpJkaMq=z}Oiz!tWk>TtioIwcAJany1Wq)p6}z+ev57YlG1X~vqY=NP?~g)C=c^k&9vrjntB;`A01 c&Sm0%e=%5gS>b)kV3whlhQ#dI$*ET2Usls*$N&HU literal 0 HcmV?d00001 diff --git a/test/text/test_multi_cell.py b/test/text/test_multi_cell.py index 0f9348280..8f5612570 100644 --- a/test/text/test_multi_cell.py +++ b/test/text/test_multi_cell.py @@ -545,6 +545,16 @@ def test_multi_cell_with_padding_check_input(): pdf.multi_cell(0, 5, LONG_TEXT, border=1, padding=(5, 5, 5, 5, 5, 5)) +def test_multi_cell_with_padding_and_page_break(tmp_path): # issue #1395 + pdf = FPDF() + pdf.add_page() + pdf.set_font("Helvetica") + pdf.multi_cell( + w=0, text="Hello, this is a sample PDF!" * 300, padding=[0, 0, 50, 0] + ) + assert_pdf_equal(pdf, HERE / "multi_cell_with_padding_and_page_break.pdf", tmp_path) + + def test_multi_cell_return_value(tmp_path): pdf = FPDF() pdf.add_page()