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

samuel toh picture samuel toh · Dec 21, 2016 · Viewed 8.9k times · Source

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?

Answer

larp picture larp · Jul 18, 2019

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>