fpdf2
fpdf2 copied to clipboard
[table] Feature request: support "colspanning-cells" breaking over page jumps
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"]] * 50
with pdf.table(data) as table:
pass
pdf.output("overly_long_tablespan.pdf")
raises
Traceback (most recent call last):
File "c:\Users\User\Desktop\Platform-Integration\API\test_graph.py", line 14, in <module>
with pdf.table(data) as table:
^^^^^^^^^^^^^^^
File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\contextlib.py", line 144, in __exit__
next(self.gen)
File "C:\Users\User\Desktop\Platform-Integration\API\myvenv\Lib\site-packages\fpdf\fpdf.py", line 5602, in table
table.render()
File "C:\Users\User\Desktop\Platform-Integration\API\myvenv\Lib\site-packages\fpdf\table.py", line 257, in render
raise ValueError(
ValueError: The row with index 1 is too high and cannot be rendered on a single page
Hi @slkoo-core
Thank you for the clear report with a minimal test case.
If you replace your * 50 by a factor * 29 instead, fpdf2 will be able to render the document.
The resulting PDF contains a really high first cell spanning over 29 cells in columns 2 & 3:
Currently, fpdf2 does not support "spanning-cell-break" over page jumps.
Contributions & PRs are welcome to implement this 🙂
Thank you. That is the expected output and there is usage for such spanning-cell across page break, which could span across multiple pages. We are unable to control how many rows in such cases (e.g. class name list)
@allcontributors please add @slkoo-core for bug
Thank you. That is the expected output and there is usage for such spanning-cell across page break, which could span across multiple pages. We are unable to control how many rows in such cases (e.g. class name list)
fpdf2 is 100% volunteer-powered.
Would you like to work on a PR to implement this? 🙂
hey can i take this on ? is it up for grabs ?
hey can i take this on ? is it up for grabs ?
Yes it is! I think that you can take this on 🙂 If @slkoo-core prefers to handle it, he will surely mention it.
on it.
i don't think ill be able to fix this , anyone else is welcome !
Hey sorry to bother I'm wondering if the issue / enhancement is still available and if yes can i look into it and is there more information or should I gather them on my side ?
Hi @Neyhlo
You are very welcome to help & contribute to fpdf2 by tackling this feature request 🙂
Are you volunteering as part of Hacktoberfest?
As a starting point, I would recommend that you get a look at:
- our development guidelines: https://py-pdf.github.io/fpdf2/Development.html
- the
Tableclass source code: https://github.com/py-pdf/fpdf2/blob/master/fpdf/table.py - the
Tableclass unit tests: test/table/test_table.py & test/table/test_table_rowspan.py
hey @Lucas-C
I'm volunteering as part of a school project so it will be all year long and maybe more
Thanks for all the links I'll take a good look into all of it and try to help