Page number on all mpdf pages

Asked

Viewed 2,840 times

1

How to make the page number appear in the footer on all pages? I have briefly the code below, but the way it is, the page number only appears on the last page, how to 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();

2 answers

2


I know it’s been a long time since the question was asked, but it’s worth noting: In double-sided documents, you need to define different statements for footers and even-odd page headers; In simple documents, set 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

  • because the style of odd and even pages needs to be different?

  • I edited the answer. It does not change the style (not necessarily). In your question you are using the mode RUNTIME to set the footer, and these are the library rules for this mode. Test this code in your environment, @Alexandremartinsmontebelo. It has 4 pages and all are numbered sequentially ;)

  • got it, qto to RUNTIME mode, where that "Desdeclaro" it? I could not see it comparing the codes.

  • 1

    Changing the mode of declaring the variable that defines the footer. See: Ways to declare headers and footers. This one would be the way NAMED: Method 4, who uses DefHeaderByName(). Both the question and the answer are using RUNTIME HTML with SetHTMLFooter().

  • Got it, thanks for the tips.

0

I put your code here in mine and it’s working

$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);
  • continues with the same problem here :/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.