mPDF - footer is working only on last page

Alexandre Martins Montebelo picture Alexandre Martins Montebelo · Apr 5, 2016 · Viewed 11.7k times · Source

I saw the other similar questions here, but I couldn't resolve my problem. My problem is: the header is working normally in all pages, but the footer is showing only on last page.

<?
$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');

$cabecalho = '<div>header</div>'; 
$paragrafo = '<div>body</div>'; 
$stylesheet = "table{
                  width: 100%;
                  text-align:center;
                  border: 2px solid black;
               }
";

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

$mpdf->WriteHTML($stylesheet, 1);
$mpdf->WriteHTML($paragrafo);

$mpdf->SetFooter($footer);

$mpdf->Output();
exit;
?>

What's the problem with footer here?

Answer

Kunal Nigam picture Kunal Nigam · Apr 5, 2016

try to put setFooter() before WriteHTML()

$mpdf->SetHTMLHeader($cabecalho);
$mpdf->SetFooter($footer);
$mpdf->WriteHTML($stylesheet, 1);
$mpdf->WriteHTML($paragrafo);
$mpdf->AddPage('','','','b','off');
$mpdf->Output();