fpdf2 icon indicating copy to clipboard operation
fpdf2 copied to clipboard

[table] Feature request: support "colspanning-cells" breaking over page jumps

Open slkoo-cc opened this issue 6 months ago • 12 comments

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

slkoo-cc avatar Jun 03 '25 02:06 slkoo-cc

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: Image

Currently, fpdf2 does not support "spanning-cell-break" over page jumps.

Contributions & PRs are welcome to implement this 🙂

Lucas-C avatar Jun 03 '25 10:06 Lucas-C

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)

slkoo-cc avatar Jun 04 '25 05:06 slkoo-cc

@allcontributors please add @slkoo-core for bug

Lucas-C avatar Jun 04 '25 08:06 Lucas-C

@Lucas-C

I've put up a pull request to add @slkoo-core! :tada:

allcontributors[bot] avatar Jun 04 '25 08:06 allcontributors[bot]

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? 🙂

Lucas-C avatar Jun 04 '25 08:06 Lucas-C

hey can i take this on ? is it up for grabs ?

GarvThakral avatar Jun 05 '25 19:06 GarvThakral

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.

Lucas-C avatar Jun 05 '25 19:06 Lucas-C

on it.

GarvThakral avatar Jun 05 '25 20:06 GarvThakral

i don't think ill be able to fix this , anyone else is welcome !

GarvThakral avatar Jun 08 '25 08:06 GarvThakral

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 ?

Neyhlo avatar Oct 17 '25 13:10 Neyhlo

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:

Lucas-C avatar Oct 17 '25 13:10 Lucas-C

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

Neyhlo avatar Oct 17 '25 14:10 Neyhlo