Level 88
Have you tried to chunk the results per page?
$results = App\DeliveryOrder::chunk(20, function ($query) {
// Your query
});
And if you know add a page for each result
foreach ($results as $dos) {
// Add page in pdf
}
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have a long list of items (About 200) I want to display on PDF file, but DomPDF cannot automaticcaly create a new page when the first page is full.
I want to display like some contents on the first page and the rest on the second.
This is what I have tried
$dos = App\DeliveryOrder::has('printed_job')->where('icd_id', $request->get('icd_id'))->get();
return PDF::loadView('reports.disp', compact('dos','icd'))->setPaper('A4')->setOrientation('portrait')->stream();
The above code works well when I try with few items like 10.
I have tried putting this as advised by someone on Stackoverflow
<tr style="page-break-after: always;">
on the table row but it seems it doesnt solve the problem.
Please help. Thanks
I have managed to solve it.
$dos = DeliveryOrder::has('printed_job')->where('icd_id', $request->get('icd_id'))->get();
$results = $dos->chunk(20);
$icd = Icd::find( $request->get('icd_id') )->name;
return PDF::loadView('reports.disp', compact('results','icd'))->setPaper('A4')->setOrientation('portrait')->stream();
<?php $i = 1; ?>
@foreach($results as $dos)
<table>
<thead>
<tr>
<th class="service" style="font-weight: bold;">NO</th>
<th class="desc" style="font-weight: bold;">DO NUMBER</th>
<th class="desc" style="font-weight: bold;">BL NUMBER</th>
<th class="desc" style="font-weight: bold;">VESSEL, VOY</th>
</tr>
</thead>
<tbody>
@foreach($dos as $do)
<tr>
<td class="service">{{ $i++ }}</td>
<td class="desc">{{ $do->do }}</td>
<td class="desc">{{ $do->hbl }}</td>
<td class="desc">{{ $do->vessel }}</td>
</tr>
@endforeach
</tbody>
</table>
<span style="page-break-after:always;"></span>
@endforeach
```
Please or to participate in this conversation.