0

I integrate dompdf inside my laravel projet. I return a blade view as PDF and works all fine but I don't know how to show number of pages.

For example I want to show in header Page 1 of 4 ... Page 2 of 4 ... etc

This is how I return the PDF:

$pdf = PDF::loadView('file-pdf', $data);
  return $pdf->download('filename.pdf');
user3242861
  • 1,839
  • 12
  • 48
  • 93
  • Does this answer your question? [How to add page number for every page in laravel dompdf?](https://stackoverflow.com/questions/41272819/how-to-add-page-number-for-every-page-in-laravel-dompdf) – Nico Haase Jun 01 '23 at 07:01

1 Answers1

0

Try to add this to your vie. Make sure you have "DOMPDF_ENABLE_PHP" => true, in dompdf.php. also, make sure your content doesn't pass php code unescaped since that would leave arbitrary code to be run as said in dompdf docs.

<script type="text/php">
if (isset($pdf)) {
   $font = $fontMetrics->getFont("Arial", "bold");
   $pdf->page_text(555, 745, "Page {PAGE_NUM}/{PAGE_COUNT}", $font, 7, array(0, 0, 0));
}
</script>
Sérgio Reis
  • 2,483
  • 2
  • 19
  • 32