Skip to content

Start a table with page-break-before on a new page - #576

Merged
jakejackson1 merged 2 commits into
fix/552-break-propertiesfrom
fix/552-table-page-break-before
Sep 30, 2026
Merged

jakejackson1 merged 2 commits into
fix/552-break-propertiesfrom
fix/552-table-page-break-before

Conversation

@jakejackson1

Copy link
Copy Markdown
Member

Stacked on #569.

Problem

page-break-before on a table was ignored. table { page-break-before: always } with <p>aa</p><table>…bb…</table> left bb on page 1. Table::open() read PAGE-BREAK-AFTER and PAGE-BREAK-INSIDE but never PAGE-BREAK-BEFORE, so break-before: page from #569 did nothing on a table either.

Change

  • Table::open() looks ahead at a top-level table's CSS with PreviewBlockCSS(), the look-ahead BlockTag::open() uses. For always, left or right it breaks the page before doing anything else. That order matters. The forced break closes the open blocks and opens them again on the new page, and Table::open() then draws the top of those blocks before the table. With the break later in open(), a table inside a bordered div was drawn above the div's reopened border instead of inside it.
  • The forced-break steps move into Tag::forcePageBreak(): save the block and inline state, _preForcedPagebreak(), AddPage() to the next page, odd page or even page, _postForcedPagebreak(), then restore. page-break-after on blocks (BlockTag::close()) and tables (Table::close()) had identical copies of those steps, and now call the helper too.
  • A nested table ignores the property, as it does page-break-after and page-break-inside.

Not in this PR: page-break-before: always on a row, and page-break-after: avoid protecting only one line. Neither is a quick fix; both stay in #552.

No existing snapshot fixture changed.

Tests

  • TablePageBreakBeforeTest:

    • Records the page of each marked piece of text for always, break-before: page, right and left with mirrored margins, and a rule in a style sheet. Each starts the table on the page it names, and the text after the table follows it.
    • auto, avoid and a nested table do not break.
    • A table that breaks inside a bordered block is drawn on the new page below the block's reopened border and padding (1 mm + 3 mm lower than on its own), with the rest of the block after it.
  • TextRecordingMpdf records the top of each line it draws as well, for that test.

  • TablePageBreakBeforeSnapshotTest (table-page-break-before) has three pages, each with a caption saying what should be seen:

    • a table moved to page 2 by a style sheet rule;
    • a table with break-before: page inside a red box, drawn on page 3 inside the box, which is drawn again around it;
    • a nested table with page-break-before: always that stays in its cell.

    Before this change the whole document was on one page.

With the source changes reverted, the new tests fail.

Checks

  • composer test: OK. 4524 tests, 31 skipped for missing optional packages or ungenerated data. The snapshot suite ran with Imagick and Ghostscript.
  • composer cs: clean.
  • PHPStan 2.2: no errors.

Part of #552. Part of #520.

🤖 Generated with Claude Code

@jakejackson1 jakejackson1 added bug Something isn't working create-upstream-pr labels Sep 29, 2026
@jakejackson1
jakejackson1 force-pushed the fix/552-table-page-break-before branch from f0bd433 to 41833c0 Compare September 29, 2026 08:39
@jakejackson1
jakejackson1 force-pushed the fix/552-break-properties branch from 9dac6e8 to c2def87 Compare September 29, 2026 09:49
@jakejackson1
jakejackson1 force-pushed the fix/552-table-page-break-before branch from 41833c0 to 829702f Compare September 29, 2026 09:49
@jakejackson1
jakejackson1 force-pushed the fix/552-table-page-break-before branch from 829702f to 96fcd6b Compare September 29, 2026 22:21
@jakejackson1
jakejackson1 force-pushed the fix/552-break-properties branch 2 times, most recently from 601dc86 to fea9f80 Compare September 29, 2026 22:23
@jakejackson1
jakejackson1 force-pushed the fix/552-table-page-break-before branch from 96fcd6b to be9b439 Compare September 29, 2026 22:23
`page-break-before` and `break-before` on a table were never read, so
`table { page-break-before: always }` left the table on the page before.
On a top-level table, `always`, `left` and `right` now break the page as
they do before a block. The break comes before the table closes the blocks
it opens in, so those blocks are opened again around the table on the new
page. The steps of the forced break move to `Tag::forcePageBreak()`, which
`page-break-after` on blocks and tables uses as well.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jakejackson1
jakejackson1 force-pushed the fix/552-table-page-break-before branch from be9b439 to e836647 Compare September 29, 2026 23:45
@jakejackson1
jakejackson1 force-pushed the fix/552-break-properties branch from fea9f80 to def1400 Compare September 29, 2026 23:45
@jakejackson1
jakejackson1 merged commit 7071ba7 into fix/552-break-properties Sep 30, 2026
10 checks passed
@jakejackson1

Copy link
Copy Markdown
Member Author

This was merged into fix/552-break-properties after #569 had already been squash-merged into gravitypdf, so the change never reached gravitypdf. #622 replaces it, rebased onto gravitypdf.

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

Labels

bug Something isn't working create-upstream-pr

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant