mpdf / mpdf

PHP library generating PDF files from UTF-8 encoded HTML
https://mpdf.github.io
GNU General Public License v2.0
4.37k stars 1.06k forks source link

Page break inside: 'avoid' can cause table background to be copied to previous page #570

Open RyanDwyer opened 6 years ago

RyanDwyer commented 6 years ago

I found this bug / would like to have this new functionality

When you have markup like this:

<table>...</table>

<div style="page-break-inside:avoid">
    <table bgcolor="red">...</table>
</div>

...and mPDF decides to move the page break div to a new page, the previous page will contain the background color of the table which was moved to the new page.

The first table is required for this bug to present itself.

This is mPDF and PHP version and environment (fpm/cli etc) I am using

mPDF 7.0.2 PHP 7.0.25

This is a PHP code snippet I use

<?php
require 'vendor/autoload.php';

$mpdf = new Mpdf\Mpdf;

$before = str_repeat('<p>Before</p>', 20);
$after = str_repeat('<p>After</p>', 10);

$html = <<<HTML
    $before

    <table>
        <tr>
            <td>Normal table cell</td>
        </tr>
    </table>

    <div style="page-break-inside:avoid">
        <table>
            <tr>
                <td bgcolor="red">Red table cell</td>
            </tr>
        </table>

        $after
    </div>
HTML;

$mpdf->writeHtml($html);
$mpdf->output();

Example of incorrect rendering

image

JoseCorralesN commented 2 years ago

Why this solution is not added yet to main branch? it works!

a-r-m-i-n commented 2 months ago

I can confirm, that this issue still appears