Skip to content
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

FPDF.unbreakable() drops table instead of adding page break beforehand #1230

Open
nocalla opened this issue Jul 20, 2024 · 1 comment
Open

Comments

@nocalla
Copy link

nocalla commented Jul 20, 2024

Error details
In the below example, a series of 10 tables of two rows each is created using the unbreakable context manager based on the logic described here.

Instead of the page break triggering before the unbreakable context manager as described, the table that triggers the page break (which should have cells labelled Test 31 to Test 37) does not get displayed.

This is perhaps down to me not fully understanding the syntax around using unbreakable, but I don't think so! I'm open to correction, of course!

Minimal code

from itertools import batched

import fpdf

PDF = fpdf.FPDF()
PDF.set_font("Helvetica", size=10)
PDF.add_page()

# create some test data
CELL_COUNT = 50
labels = [f"Test {i+1}" for i in range(CELL_COUNT)]

# group the data in batches
col_count = 5
label_groups = list(batched(labels, col_count))

# generate a separate table for each group with the labels as table headers
for group in label_groups:
    with PDF.unbreakable() as doc:
        doc.ln()
        with doc.table(
            text_align="CENTER",
            gutter_width=10,
        ) as table:
            table.row(group)
            row = table.row()
            for item in group:
                row.cell("DON'T PANIC - CELL LEFT INTENTIONALLY BLANK")

PDF.output("unbreakable_bug_test.pdf")

Environment
Please provide the following information:

  • Operating System: Windows 11
  • Python version: 3.12.1
  • fpdf2 version used: 2.7.9
@nocalla nocalla added the bug label Jul 20, 2024
@nocalla nocalla changed the title FPDF.unbreakable() doesn't work well with table() FPDF.unbreakable() drops table instead of adding page break beforehand Jul 20, 2024
@gmischler
Copy link
Collaborator

Thanks for reporting this, @nocalla !

As you can see in #1200, the table code is currently under a fundamental overhaul. I don't know if there is a quick fix possible for the current code, but otherwise you'll have to be patient until that PR lands. It will be more flexible about page breaks in general, and hopefully solve your problem as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants