Skip to content

Draw a repeated table header or footer with a background image without warnings (#742) - #750

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

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

Conversation

@gravitypdf-bot

Copy link
Copy Markdown

Fixes #742

Found while working on #552

Stacked on #723

Problem

A table header or footer that is drawn again on later pages raises Undefined array key "gradient" warnings on each of those pages when one of its cells or rows has a background-image loaded from a URL. The image itself is still drawn. The warnings are the only fault, but a strict error handler turns them into a failed document.

$mpdf = new \Mpdf\Mpdf();
$rows = str_repeat('<tr><td>Row</td><td>Row</td></tr>', 80);
$mpdf->WriteHTML('<table repeat_header="1">
<thead>
	<tr><th style="background-image: url(bg.jpg)">Cell image</th><th>Plain</th></tr>
	<tr style="background-image: url(bg.jpg)"><th>Row image</th><th>Row image</th></tr>
</thead>
<tbody>' . $rows . '</tbody></table>');
First page Repeated header or footer
Before image, no warning image, Undefined array key "gradient" per cell or row
After image, no warning image, no warning

Cause

TableHeaderFooter() reads $bg['gradient'] for every background layer of a header or footer cell and row without checking that the key exists. A layer from a URL has image_id and no gradient key. _tableWrite() draws the same cell on the table's first page, and it checks the key with isset() first.

This branch is stacked on #723 because #723 rewrites both of these lines into a loop over background layers. The unguarded read is still there after that rewrite, now as $bg['gradient'].

Fix

Both reads are now !empty($bg['gradient']), the same check that isset() && truthy makes elsewhere in the file.

Legacy mode

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

Tests

  • tests/Mpdf/RepeatedTableHeaderBackgroundTest.php renders a three-page table whose header cell, header row, footer cell or footer row has a background image, in both CSS modes (8 cases). It uses the PageStreams trait's assertDrawsSilently() to assert that nothing is raised, and it asserts that a pattern is painted on every page. All 8 cases fail against the src/ on Draw every layer of a multiple background (#609) #723 with the warnings from lines 13361 and 13546, 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 (12770 tests, 31 skipped, none of them snapshots; the snapshot group alone passes 219/219, none skipped)
  • composer cs: clean
  • PHPStan: same 23 errors as on gravitypdf, none new

🤖 Generated with Claude Code

gravitypdf-bot and others added 2 commits October 13, 2026 10:28
…t warnings (#742)

TableHeaderFooter() read the gradient of each background layer of a
repeated header or footer cell and row without checking it was there.
A layer read from a URL has no gradient key, so every page the header
or footer was drawn again raised "Undefined array key" warnings, which
a strict error handler turns into a failed document. The first-page
code in _tableWrite() already checks with isset().

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…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