Multi-page documents · 6 min read

Pagination

Pagination is controlled with print CSS and optional page range settings. Use CSS for where pages break, and pages() or pageRanges() when you only want part of the generated document.

Page breaks

Use modern print CSS to keep sections together or force a new page.

resources/views/pdf/report.blade.php
html
 1<style>
 2    .page-break {
 3        break-before: page;
 4    }
 5
 6    .avoid-break {
 7        break-inside: avoid;
 8    }
 9
10    tr {
11        break-inside: avoid;
12    }
13</style>

Long tables

Browser print layout can repeat table headers when you use semantic table sections. This is ideal for invoices, inventory exports, and financial reports.

Table structure
html
 1<table>
 2    <thead>
 3        <tr>
 4            <th>Description</th>
 5            <th>Amount</th>
 6        </tr>
 7    </thead>
 8    <tbody>
 9        @foreach ($items as $item)
10            <tr>
11                <td>{{ $item->description }}</td>
12                <td>{{ $item->amount }}</td>
13            </tr>
14        @endforeach
15    </tbody>
16</table>

Most document templates should be styled for print. You can also force print media mode from the render request.

Controller
php
 1return BladePDF::fromView('pdf.report', $data)
 2    ->emulateMedia('print')
 3    ->format('A4')
 4    ->render()
 5    ->download('report.pdf');

Page ranges

Use pages() or pageRanges() to return only selected pages from the generated PDF. The value is passed as a page range string.

Selected pages
php
 1BladePDF::fromView('pdf.catalog', $data)
 2    ->pages('1-3, 8, 10-12')
 3    ->render()
 4    ->pdf();

Page numbers

Add page numbers through a footer. See Headers & Footers for the full setup.

Footer HTML
html
 1<div style="font-size:10px;width:100%;text-align:center">
 2    Page <span class="pageNumber"></span> of <span class="totalPages"></span>
 3</div>

Avoid common issues

  • Avoid fixed-height wrappers around long content.
  • Use break-inside: avoid sparingly; overusing it can create large blank gaps.
  • Prefer semantic tables for tabular data.
  • Use emulateMedia('print') when your CSS separates screen and print design.
Was this page helpful?
Let us know if something's missing or unclear.