Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mPDF - footer is working only on last page

Tags:

php

footer

mpdf

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?

like image 273
alexandre9865 Avatar asked Apr 05 '16 02:04

alexandre9865


2 Answers

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();
like image 86
Kunal Nigam Avatar answered Nov 11 '22 15:11

Kunal Nigam


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

like image 4
Severino Lorilla Jr. Avatar answered Nov 11 '22 17:11

Severino Lorilla Jr.