wkhtmltopdf in PHP - problem with splitting table into pages

28 Views Asked by At

I'm using wkhtmltopdf and mikehaertl PDF plugin in PHP to generate PDFs.

I have troubles properly splitting tables in PDF. In the picture below, I want that rows can be splitted in the middle, without moving them to another page. It's totally ok for me to have text splitted across two pages:

enter image description here

Here's the HTML/PHP code to generate that table:

<div style="page-break-before: always;">
    <h3>Lorem ipsum</h3>
    <?php foreach ($document->areas as $area): ?>
        <table style="page-break-after: always;">
            <tr>
                <td colspan="2" style="font-weight: bold; background-color: lightblue;">
                    <?= $area->lorem_ipsum ?>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <?php foreach ($area->fields as $field): ?>
                        <table>
                            <tr style="background-color: lightgrey;">
                                <td><?= $field->lorem_ipsum ?></td>
                                <td><?= $field->lorem_ipsum ?></td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    <strong>lorem_ipsum:</strong><br>
                                    <?= nl2br($field->lorem_ipsum) ?>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    <strong>lorem_ipsum:</strong><br>
                                    <?= nl2br($field->lorem_ipsum) ?>
                                </td>
                            </tr>
                        </table>
                    <?php endforeach; ?>
                </td>
            </tr>
        </table><br>
    <?php endforeach; ?>
</div>

I have tried with different combinations of page-break-inside on parent and child elements

0

There are 0 best solutions below