How to add page number for every page in laravel dompdf?
Try this one.
<style>
.pagenum:before {
content: counter(page);
}
</style>
<body>
<span class="pagenum"></span>
<table>
<tr>
<th>header1</th>
<th>header2</th>
<th>header3</th>
</tr>
<tr>
<td>content-row-1</td>
<td>content-row-1</td>
<td>content-row-1</td>
</tr>
<tr>
<td>content-row-2</td>
<td>content-row-2</td>
<td>content-row-2</td>
</tr>
</table>
</body>
Follow below steps to achieve it:
- Enable DOMPDF_ENABLE_PHP
from /config/dompdf.php
- Publish vendor file via php artisan vendor:publish command
- Pass $pdf
object from controller:
- Add below code inside the view file:
<script type="text/php">
if ( isset($pdf) ) {
$font = Font_Metrics::get_font("helvetica", "bold");
$pdf->page_text(72, 18, "Header: {PAGE_NUM} of {PAGE_COUNT}", $font, 6, array(0,0,0));
}
</script>
You can get more idea from Page count and page number