forked from reingart/pyfpdf
-
Notifications
You must be signed in to change notification settings - Fork 345
Support rowspans taller than one page (#1460) #1820
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
Draft
jjudyyang
wants to merge
4
commits into
py-pdf:master
Choose a base branch
from
jjudyyang:issue-1460-rowspan-page-break
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| from fpdf import FPDF | ||
| from fpdf.enums import TableSpan | ||
|
|
||
| pdf = FPDF() | ||
|
|
||
| pdf.auto_page_break = True | ||
| pdf.set_font("Arial", size=12) | ||
| pdf.add_page() | ||
|
|
||
| data = [ | ||
| ["Header 1", "Header 2", "Header 3"], | ||
| ["Data 1", "Data 2", "Data 3"], | ||
| ] + [[TableSpan.ROW, "Data 5", "Data 6"]] * 30 #this seems to be the threshold -> 32 rows of this size | ||
|
|
||
| with pdf.table(data) as table: | ||
| pass | ||
|
|
||
| pdf.output("overly_long_tablespan.pdf") | ||
| print("Wrote overly_long_tablespan.pdf") |
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,9 @@ | ||
| from pathlib import Path | ||
|
|
||
| from fpdf import FPDF, FontFace | ||
| from fpdf.enums import TableSpan | ||
| from fpdf.enums import TableHeadingsDisplay, TableSpan | ||
|
|
||
| from test.conftest import assert_pdf_equal | ||
| from test.conftest import LOREM_IPSUM, assert_pdf_equal | ||
|
|
||
| HERE = Path(__file__).resolve().parent | ||
| IMG_DIR = HERE.parent / "image" | ||
|
|
@@ -223,6 +223,77 @@ def test_table_with_rowspan_and_pgbreak(tmp_path): | |
| assert_pdf_equal(pdf, HERE / "table_with_rowspan_and_pgbreak.pdf", tmp_path) | ||
|
|
||
|
|
||
| #helper function for issue #1460 data | ||
| def _issue_1460_table_data(span_extra_rows: int = 30): | ||
| """Minimal data from issue #1460 (rowspan via TableSpan.ROW).""" | ||
| return [ | ||
| ["Header 1", "Header 2", "Header 3"], | ||
| ["Data 1", "Data 2", "Data 3"], | ||
| ] + [[TableSpan.ROW, "Data 5", "Data 6"] for _ in range(span_extra_rows)] | ||
|
|
||
|
|
||
| def test_table_rowspan_issue_1460_multipage(tmp_path): | ||
| # Issue #1460: rowspan taller than one page must render across multiple pages. | ||
| pdf = FPDF() | ||
| pdf.auto_page_break = True | ||
| pdf.set_font("Helvetica", size=12) | ||
| pdf.add_page() | ||
| with pdf.table(_issue_1460_table_data(30)): | ||
| pass | ||
| assert_pdf_equal(pdf, HERE / "table_rowspan_issue_1460_multipage.pdf", tmp_path) | ||
|
|
||
|
|
||
| def test_table_rowspan_issue_1460_repeat_headings(tmp_path): | ||
| # Same as multipage case, but headings must repeat after each page break. | ||
| pdf = FPDF() | ||
| pdf.auto_page_break = True | ||
| pdf.set_font("Helvetica", size=12) | ||
| pdf.add_page() | ||
| with pdf.table( | ||
| _issue_1460_table_data(30), | ||
| repeat_headings=TableHeadingsDisplay.ON_TOP_OF_EVERY_PAGE, | ||
| ): | ||
| pass | ||
| assert_pdf_equal( | ||
| pdf, HERE / "table_rowspan_issue_1460_repeat_headings.pdf", tmp_path | ||
| ) | ||
|
|
||
|
|
||
| def test_table_rowspan_across_pages_merged_cell_long_text(tmp_path): | ||
| # Rowspan anchor cell contains enough text to overflow; span crosses page breaks. | ||
| long_text = (LOREM_IPSUM + "\n\n") * 2 | ||
| data = [ | ||
| ["Header 1", "Header 2", "Header 3"], | ||
| [long_text, "Col B", "Col C"], | ||
| ] + [[TableSpan.ROW, f"R{i}", f"R{i}"] for i in range(35)] | ||
| pdf = FPDF() | ||
| pdf.auto_page_break = True | ||
| pdf.set_font("Helvetica", size=12) | ||
| pdf.add_page() | ||
| with pdf.table(data): | ||
| pass | ||
| assert_pdf_equal( | ||
| pdf, HERE / "table_rowspan_across_pages_merged_cell_long_text.pdf", tmp_path | ||
| ) | ||
|
|
||
| def test_table_rowspan_issue_1460_merged_cell_long_text_no_header(tmp_path): | ||
| # Same as multipage case, but no header | ||
| long_text = (LOREM_IPSUM + "\n\n") * 2 | ||
| data = [ | ||
| ["Text", "Header 2", "Header 3"], | ||
| [long_text, "Col B", "Col C"], | ||
| ] + [[TableSpan.ROW, f"R{i}", f"R{i}"] for i in range(35)] | ||
| pdf = FPDF() | ||
| pdf.auto_page_break = True | ||
| pdf.set_font("Helvetica", size=12) | ||
| pdf.add_page() | ||
| with pdf.table(data, first_row_as_headings=False): | ||
| pass | ||
| assert_pdf_equal( | ||
| pdf, HERE / "table_rowspan_issue_1460_merged_cell_long_text_no_header.pdf", tmp_path | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The actions pipeline is failing because this file has not been commited. |
||
| ) | ||
|
|
||
|
|
||
| def test_table_with_rowspan_images(tmp_path): | ||
| # Verify that the rowspans interact correctly with pagebreaks | ||
| pdf = FPDF() | ||
|
|
||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test and
test_table_rowspan_issue_1460_multipage()seem to produce identical files - you could even reference the same PDF. Maybe the idea was to testTableHeadingsDisplay.NONEto cover both paths?