Search code examples
htmlcssprintingmpdfexport-to-pdf

Do not break content inside div


How do I tell mpdf to move div content to next page instead of breaking it in the middle? I found some mpdf-specific tags but it did not help me. Any ideas?

<div> <!-- content inside div should not be broken -->
    <h1>Heading</h1>
    <ul>
        <li n:foreach="$teacherSummary as $teacher => $children">
            {$teacher}: {array_unique($children)|implode:', '}
        </li>
    </ul>
    <p><strong>{$event->note}</strong></p>
</div>

Solution

  • There is CSS property page-break-inside that works in mpdf as well.

    Usage:

    <div style="page-break-inside:avoid !important;">
        <h1>Heading</h1>
        <ul>
            <li n:foreach="$teacherSummary as $teacher => $children">
                {$teacher}: {array_unique($children)|implode:', '}
            </li>
        </ul>
        <p><strong>{$event->note}</strong></p>
    </div>