12

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?

alexandre9865
  • 493
  • 2
  • 9
  • 24

2 Answers2

19

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();
Kunal Nigam
  • 326
  • 1
  • 6
  • This breaks `setAutoBottomMargin => 'stretch'` & defined `margin_bottom` :/ – kaarto Jun 29 '19 at 14:03
  • 1
    Ah, nevermind! After hours of struggling I finally got mine working! `SetHTMLFooter` needs to be set inbetween stylesheets and html! Then it appears on every page, and custom bottom margins works. – kaarto Jun 29 '19 at 14:06
4

use SetHTMLFooter() and add it before WriteHTML() right after SetHTMLHeader()

hope that will resolve the footer issue

Other Info:

void SetHTMLFooter(String $html, string $side)

void SetFooter( $footer, $side)

SetFooter is already deprecated but will still work..

$footer = array(
    'L' => array {
        'content' => '',
        'font-size' => 10,
        'font-style' => 'B',
        'font-family' => '',
        'color' => '#000000'
    },
    'C' => array {
        'content' => '',
        'font-size' => 10,
        'font-style' => 'B',
        'font-family' => '',
        'color' => '#000000'
    },
    'R' => array {
        'content' => '',
        'font-size' => 10,
        'font-style' => 'B',
        'font-family' => '',
        'color' => '#000000'
    },
    'line' => 1
);

$side can be O for Odd pages, E for Even pages or blank for all pages.

For the documentation check this link

http://www.mpdfonline.com/repos/mpdfmanual.pdf

Severino Lorilla Jr.
  • 1,637
  • 4
  • 20
  • 33