Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

moses's avatar
Level 2

How to add page number for every page in laravel dompdf?

I get from here : https://github.com/barryvdh/laravel-dompdf

My controller is like this :

public function listdata()
{
    $pdf=PDF::loadView('print_tests.test_pdf');
    $pdf->setPaper('L', 'landscape');
    return $pdf->stream('test_pdf.pdf');
}

My view is like this :

<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>

I want every page there is a page number

Is there any people who can help me?

0 likes
8 replies
jlrdw's avatar

Did you read the composer file? It uses exactly what I said it uses.

migsAV's avatar

Hi, check out this link

https://stackoverflow.com/questions/41272819/how-to-add-page-number-for-every-page-in-laravel-dompdf

And then there are the more settings you can add

if (isset($pdf)) {
    $x = 250;
    $y = 10;
    $text = "Page {PAGE_NUM} of {PAGE_COUNT}";
    $font = null;
    $size = 14;
    $color = array(255,0,0);
    $word_space = 0.0;  //  default
    $char_space = 0.0;  //  default
    $angle = 0.0;   //  default
    $pdf->page_text($x, $y, $text, $font, $size, $color, $word_space, $char_space, $angle);
}

https://github.com/barryvdh/laravel-dompdf/issues/37

larp's avatar

Try this one:

<style>
.pagenum:before {
        content: counter(page);
}
header {
    /* add some css */
}
</style>


<header>
  <span class="pagenum"></span>
</header>
2 likes

Please or to participate in this conversation.