1

I have been trying to insert page number using the package barryvdh/laravel-dompdf. But so far I am unsuccessful. How do I do this?

Nasif Md. Tanjim
  • 3,862
  • 4
  • 28
  • 38

1 Answers1

3

Look here https://code.google.com/p/dompdf/wiki/FAQ

Also here is question on github https://github.com/barryvdh/laravel-dompdf/issues/37

Found my answer by looking over the dompdf_config.inc.php file. As it turns out, DOMPDF_ENABLE_PHP is set to false thus causing the inline php script to be ignored. I simply edited dompdf_config.custom.inc.php to the following and all is fine and working with the later code in the view.

In dompdf/dompdf_config.custom.inc.php

<?php
    define("DOMPDF_ENABLE_PHP", true);

Then, in my html file

<body>
    <script type="text/php">
        if ( isset($pdf) ) {
            $font = Font_Metrics::get_font("helvetica", "bold");
            $pdf->page_text(72, 18, "{PAGE_NUM} of {PAGE_COUNT}", $font, 6, array(255,0,0));
        }
    </script>
    <div

If you go this route, don't forget to restart Apache

source How to get page number on dompdf PDF when using "view"

Community
  • 1
  • 1
Adnan
  • 7,825
  • 3
  • 23
  • 41
  • Note that for version >= 0.7, you should be using [Dennis Ameling's solution](https://stackoverflow.com/a/38788676/5727643). – Amin NAIRI Oct 25 '17 at 08:26
  • is there any way that we can use a dynamic variable in each page instead of PAGE_NUM? Ex: different usernames on each page – Forrest Dec 12 '19 at 04:22