Skip to content

Draw a split table's background image on its later pages without warnings (#742) - #753

Open
gravitypdf-bot wants to merge 2 commits into
feature/609-multiple-backgroundsfrom
fix/742-split-table-background-warnings
Open

gravitypdf-bot wants to merge 2 commits into
feature/609-multiple-backgroundsfrom
fix/742-split-table-background-warnings

Conversation

@gravitypdf-bot

Copy link
Copy Markdown

Follow-up to #742

Found while working on #552

Stacked on #723

Problem

A table split across pages raises an Undefined array key "gradient" warning on each later page when the table has a background-image from a URL. The image is still drawn on every page. The warnings are the only fault, but a strict error handler turns them into a failed document. #742 (fixed by #750) had the same fault in a repeated header or footer; this is the same read in the code that draws the table's own background again on its later pages.

$mpdf = new \Mpdf\Mpdf();
$mpdf->WriteHTML('<table style="background-image: url(bg.jpg)">'
	. str_repeat('<tr><td>Row</td><td>Row</td></tr>', 80)
	. '</table>');
First page Later pages
Before image, no warning image, Undefined array key "gradient"
After image, no warning image, no warning

Cause

_tableWrite() reads $bg['gradient'] for every layer of the table's background-image without checking that the key exists. It does this when it draws the background again on a later page of a split table. A layer from a URL has image_id and no gradient key. The same read on gravitypdf is at src/Mpdf.php:23460. #723 rewrites it into its loop over background layers, which is why this branch is stacked on #723.

Fix

The read is now !empty($bg['gradient']), the same guard #750 uses for the header and footer reads.

Legacy mode

This is a fix for a warning, and it applies in both cssModes. Nothing on the page changes in either mode.

Tests

  • TableBackgroundTest::testASplitTableWithABackgroundImageDrawsItOnEveryPageWithoutWarnings runs in both CSS modes (it uses the DrawnStyles modes provider). It renders a table with a background image that splits across pages and uses assertDrawsSilently() to assert that nothing is raised. It also asserts that the image pattern is painted on every page. Both cases fail against the src/ on Draw every layer of a multiple background (#609) #723 with the warning at line 23540, and they pass with the fix.
  • No snapshot test. The image was drawn before and is drawn the same way after, so no page changes and a snapshot could not tell the two apart.

Checks

  • composer test: OK (12764 tests, 31 skipped, none of them snapshots; the snapshot group alone passes 219/219)
  • composer cs: clean
  • PHPStan: same 23 errors as on gravitypdf, none new

CHANGELOG-GRAVITYPDF.md gets its own line next to #750's, and both PRs add the [#742] link definition at the end of the file. Whichever merges second will conflict there; keep one of the two definitions.

🤖 Generated with Claude Code

gravitypdf-bot and others added 2 commits October 13, 2026 10:38
…ings (#742)

_tableWrite() read the gradient of each layer of a table's own
background-image, drawn again on every later page of a table split
across pages, without checking it was there. A layer read from a URL
has no gradient key, so each later page raised an "Undefined array key"
warning, which a strict error handler turns into a failed document.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ts (#742)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant