Page number on all pages mpdf

1

How do I get the page number in the footer to appear on all pages? I have briefly the code below, but the way it is, the page number only appears on the last page, how can I make it appear on all pages?

$mpdf = new mPDF( 
                 '',    // mode - default ''
                 '',    // format - A4, for example, default ''
                 0,     // font size - default 0
                 '',    // default font family
                 15,    // margin_left
                 15,    // margin right
                 58,     // margin top
                 60,    // margin bottom
                 6,     // margin header
                 0,     // margin footer
                 'L');  // L - landscape, P - portrait
$mpdf->SetDisplayMode('fullpage');   

$footer = "<table width=\"1000\">
                   <tr>
                     <td style='font-size: 18px; padding-bottom: 20px;' align=\"right\">{PAGENO}</td>
                   </tr>
                 </table>";

$mpdf->SetHTMLFooter($footer);

$mpdf->Output();
    
asked by anonymous 25.03.2016 / 03:42

2 answers

2

I know it's been a long time since the question was asked, but note: In double-sided documents, you need to define different declarations for footers and odd and even page headers ; In simple documents, set the header and footer before writing the data. Doing this, the numbering is perfect.

$mpdf = new mPDF( 
                 '',    // mode - default ''
                 '',    // format - A4, for example, default ''
                 0,     // font size - default 0
                 '',    // default font family
                 15,    // margin_left
                 15,    // margin right
                 58,     // margin top
                 60,    // margin bottom
                 6,     // margin header
                 0,     // margin footer
                 'L');  // L - landscape, P - portrait
/* Amostra de conteudo */
$html = '<table class="table-body">';
for ($i = 1; $i <= 100; $i++) {
    $html.='<tr>
    <td width="30.3%">Forbrug '.$i.'</td>
    <td width="23.1%">Periode '.$i.'</td>
    <td width="10.76%">'.$i.' MB</td>
    <td width="9.28%">Val '.$i.'</td>
    <td width="12.9%" align="right">I alt '.$i.'</td>
    <td width="13.3%" align="right"><b>moms</b> '.$i.'</td>
    </tr>';
}
$html.= '</table>';

$mpdf->SetDisplayMode('fullpage');   
$footer = "<table width=\"1000\">
<tr>
<td style='font-size: 18px; padding-bottom: 20px;' align=\"right\">{PAGENO}</td>
</tr>
</table>";
$mpdf->SetHTMLFooter($footer);
$mpdf->WriteHTML($html);
$mpdf->Output();

Source: Headers & Footers

    
20.01.2017 / 03:02
0

I put this code here in mine and it is working, see if it works for you

$mpdf->SetDisplayMode('fullpage');

        $mpdf->AddPage('P', // L - landscape, P - portrait
            '', '', '', '',
            10, // margin_left
            10, // margin right
            5, // margin top
            5, // margin bottom
            10, // margin header
            10);
            $footer = "<table width=\"1000\">
                   <tr>
                     <td style='font-size: 18px; padding-bottom: 20px;' align=\"right\">{PAGENO}</td>
                   </tr>
                 </table>";

$mpdf->SetHTMLFooter($footer);
    $css = file_get_contents("css/minu.css");
    $mpdf->WriteHTML($css,1);
    $mpdf->WriteHTML($html);
    
25.03.2016 / 20:16