Fix: Support rowspans breaking over page jumps (#1460)#1694
Open
Neyhlo wants to merge 8 commits intopy-pdf:masterfrom
Open
Fix: Support rowspans breaking over page jumps (#1460)#1694Neyhlo wants to merge 8 commits intopy-pdf:masterfrom
Neyhlo wants to merge 8 commits intopy-pdf:masterfrom
Conversation
andersonhc
requested changes
Dec 18, 2025
Collaborator
andersonhc
left a comment
There was a problem hiding this comment.
Can you please add some tests for your feature?
/test/table/test_table.py should be the best place for it - and you can use the current tests there as inspiration
Member
|
Hi @Neyhlo Without any answer from you, we will soon close this PR. |
Author
|
Hey @Lucas-C I'm so sorry about my no call no see I was very taken by work. |
Removed commented-out code related to page breaks and ghost borders management.
|
@Lucas-C or @andersonhc, would u be able to respond and continue this PR ? |
andersonhc
requested changes
Feb 20, 2026
Collaborator
andersonhc
left a comment
There was a problem hiding this comment.
@Neyhlo @ByZay I see what you’re aiming for, but I can’t verify the behavior change yet.
- The test doesn’t evidence the change: it never calls pdf.table() or uses rowspans, so it isn’t exercising the new table logic.
- As written, the change doesn’t seem to implement what the PR claims; from the current table code, a rowspan that crosses a page boundary still triggers the same error.
Could you add a focused test that uses pdf.table() with a rowspan that must cross a page brea? That would make it clear whether the new behavior actually works.
test/table/table_colspan_break.py
Outdated
Comment on lines
+1
to
+57
| from fpdf import FPDF | ||
|
|
||
| class TablePDF(FPDF): | ||
| def active_spanning_table(self, data_list, rows_per_page=25): | ||
| self.set_font("helvetica", size=11) | ||
| col_widths = [60, 60, 60] | ||
| self.set_fill_color(200, 200, 200) | ||
| headers = ["Header 1", "Header 2", "Header 3"] | ||
|
|
||
| def draw_header(): | ||
| for i, header in enumerate(headers): | ||
| self.cell(col_widths[i], 10, header, border=1, fill=True) | ||
| self.ln() | ||
|
|
||
| draw_header() | ||
|
|
||
| for group in data_list: | ||
| items = group['items'] | ||
| label = group['label'] | ||
| for chunk_idx in range(0, len(items), rows_per_page): | ||
| chunk = items[chunk_idx:chunk_idx + rows_per_page] | ||
| if self.get_y() > 250: | ||
| self.add_page() | ||
| draw_header() | ||
|
|
||
| display_label = f"{label}\n" if chunk_idx > 0 else label | ||
|
|
||
| y_start = self.get_y() | ||
| self.multi_cell(col_widths[0], 10, display_label, border=1, align='C') | ||
| y_after_label = self.get_y() | ||
|
|
||
| self.set_xy(self.l_margin + col_widths[0], y_start) | ||
| self.cell(col_widths[1], 10, "", border=1) | ||
| self.cell(col_widths[2], 10, chunk[0], border=1) | ||
| self.ln() | ||
|
|
||
| for item in chunk[1:]: | ||
| if self.get_y() > 270: | ||
| self.add_page() | ||
| draw_header() | ||
| self.multi_cell(col_widths[0], 10, f"{label}\n(suite)", border=1, align='C') | ||
| self.set_xy(self.l_margin + col_widths[0], self.get_y() - 10) | ||
|
|
||
| self.set_x(self.l_margin + col_widths[0]) | ||
| self.cell(col_widths[1], 10, "", border=1) | ||
| self.cell(col_widths[2], 10, item, border=1) | ||
| self.ln() | ||
|
|
||
| pdf = TablePDF() | ||
| pdf.add_page() | ||
|
|
||
| data = [ | ||
| {"label": "Data 1", "items": [f"Ligne {i}" for i in range(100)]} | ||
| ] | ||
|
|
||
| pdf.active_spanning_table(data, rows_per_page=25) | ||
| pdf.output("spantest2.pdf") |
Collaborator
There was a problem hiding this comment.
Suggested change
| from fpdf import FPDF | |
| class TablePDF(FPDF): | |
| def active_spanning_table(self, data_list, rows_per_page=25): | |
| self.set_font("helvetica", size=11) | |
| col_widths = [60, 60, 60] | |
| self.set_fill_color(200, 200, 200) | |
| headers = ["Header 1", "Header 2", "Header 3"] | |
| def draw_header(): | |
| for i, header in enumerate(headers): | |
| self.cell(col_widths[i], 10, header, border=1, fill=True) | |
| self.ln() | |
| draw_header() | |
| for group in data_list: | |
| items = group['items'] | |
| label = group['label'] | |
| for chunk_idx in range(0, len(items), rows_per_page): | |
| chunk = items[chunk_idx:chunk_idx + rows_per_page] | |
| if self.get_y() > 250: | |
| self.add_page() | |
| draw_header() | |
| display_label = f"{label}\n" if chunk_idx > 0 else label | |
| y_start = self.get_y() | |
| self.multi_cell(col_widths[0], 10, display_label, border=1, align='C') | |
| y_after_label = self.get_y() | |
| self.set_xy(self.l_margin + col_widths[0], y_start) | |
| self.cell(col_widths[1], 10, "", border=1) | |
| self.cell(col_widths[2], 10, chunk[0], border=1) | |
| self.ln() | |
| for item in chunk[1:]: | |
| if self.get_y() > 270: | |
| self.add_page() | |
| draw_header() | |
| self.multi_cell(col_widths[0], 10, f"{label}\n(suite)", border=1, align='C') | |
| self.set_xy(self.l_margin + col_widths[0], self.get_y() - 10) | |
| self.set_x(self.l_margin + col_widths[0]) | |
| self.cell(col_widths[1], 10, "", border=1) | |
| self.cell(col_widths[2], 10, item, border=1) | |
| self.ln() | |
| pdf = TablePDF() | |
| pdf.add_page() | |
| data = [ | |
| {"label": "Data 1", "items": [f"Ligne {i}" for i in range(100)]} | |
| ] | |
| pdf.active_spanning_table(data, rows_per_page=25) | |
| pdf.output("spantest2.pdf") | |
| from fpdf import FPDF | |
| from pathlib import Path | |
| from test.conftest import assert_pdf_equal | |
| HERE = Path(__file__).resolve().parent | |
| def test_table_colspan_break(tmp_path): | |
| def active_spanning_table(pdf, data_list, rows_per_page=25): | |
| pdf.set_font("helvetica", size=11) | |
| col_widths = [60, 60, 60] | |
| pdf.set_fill_color(200, 200, 200) | |
| headers = ["Header 1", "Header 2", "Header 3"] | |
| def draw_header(): | |
| for i, header in enumerate(headers): | |
| pdf.cell(col_widths[i], 10, header, border=1, fill=True) | |
| pdf.ln() | |
| draw_header() | |
| for group in data_list: | |
| items = group['items'] | |
| label = group['label'] | |
| for chunk_idx in range(0, len(items), rows_per_page): | |
| chunk = items[chunk_idx:chunk_idx + rows_per_page] | |
| if pdf.get_y() > 250: | |
| pdf.add_page() | |
| draw_header() | |
| display_label = f"{label}\n" if chunk_idx > 0 else label | |
| y_start = pdf.get_y() | |
| pdf.multi_cell(col_widths[0], 10, display_label, border=1, align='C') | |
| y_after_label = pdf.get_y() | |
| pdf.set_xy(pdf.l_margin + col_widths[0], y_start) | |
| pdf.cell(col_widths[1], 10, "", border=1) | |
| pdf.cell(col_widths[2], 10, chunk[0], border=1) | |
| pdf.ln() | |
| for item in chunk[1:]: | |
| if pdf.get_y() > 270: | |
| pdf.add_page() | |
| draw_header() | |
| pdf.multi_cell(col_widths[0], 10, f"{label}\n(suite)", border=1, align='C') | |
| pdf.set_xy(pdf.l_margin + col_widths[0], pdf.get_y() - 10) | |
| pdf.set_x(pdf.l_margin + col_widths[0]) | |
| pdf.cell(col_widths[1], 10, "", border=1) | |
| pdf.cell(col_widths[2], 10, item, border=1) | |
| pdf.ln() | |
| pdf = FPDF() | |
| pdf.add_page() | |
| data = [ | |
| {"label": "Data 1", "items": [f"Ligne {i}" for i in range(100)]} | |
| ] | |
| active_spanning_table(pdf, data, rows_per_page=25) | |
| assert_pdf_equal(pdf, HERE / "table_colspan_break.pdf", tmp_path, generate=True) |
Co-authored-by: Anderson Herzogenrath da Costa <andersonhc@gmail.com>
Co-authored-by: Anderson Herzogenrath da Costa <andersonhc@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1460 ---
What changes are being made?
This PR fixes a bug where tables containing large vertically spanned cells (
rowspan) would crash when exceeding the page height, and allows them to break across pages cleanly.Key changes:
ValueErrorcheck inTable.render()that prevented long rows from rendering is removed._get_span_origin) and logic in_render_table_rowto draw the vertical borders for spanned cells on continuation pages (the "ghost borders").Checklist:
A unit test is covering the code added / modified by this PR
(Note: We verified this by running existing
rowspantests which fail without the fix.)In case of a new feature, docstrings have been added, with also some documentation in the
docs/folder (N/A, this is a bug fix/enhancement to existing feature)This PR is ready to be merged
Additional comments:
The change in functionality requires updating several golden PDF files in the test suite. Specifically, tests in
test_table_rowspan.pyandtest_table_padding.pyfail because the visual output now includes the vertical borders on continuation pages, which changes the MD5 hash.The reference files (golden files) need to be updated to match the new, correct behavior.
By submitting this pull request, I confirm that my contribution is made under the terms of the GNU LGPL 3.0 license.