MPDF - Start page numbering from number 10 on the first sheet

我怕爱的太早我们不能终老 提交于 2019-12-04 04:58:18

问题


I have an application and need to print a document using the MPDF class, however necessary that the number of page start at number 43, 44, 45 and so on.

And not from the 1, 2, 3 ...

I managed to start from the 43 but only jumping a leaf. I can not insert a pagebreak.

Thanks.

Below is my code.

$mpdf = new mPDF();

$mpdf->setFooter("{PAGENO}");

$numero_paginas = "{nb}";

$mpdf->SetHTMLHeader('
<table>
    <tr>
        <td>
            <img src="img/cabecalho.png" />
        </td>
    </tr>
</table>
<hr>
');

$mpdf->SetHTMLFooter('');

$mpdf->WriteHTML('

<style type="text/css">
body{
    font-family:Arial, Times New Roman, sans-serif;
    font-size:10px;
}
</style>

' . $corpo_documento . '');

$mpdf->Output();
exit;

回答1:


From mPDF manual on page numbers:

If you want to set page numbering characteristics from the first page onwards, you should explicitly add the first page of the document using AddPage(). Note that this is normally not required, as mPDF creates a new first page automatically if required when first using WriteHTML().

So, call AddPage() after setting the footer like this:

$mpdf = new mPDF();
$mpdf->setFooter('{PAGENO}');
$mpdf->AddPage('', '', 43);



回答2:


Also, if you're adding a page by sending in an array of arguments, you can set it to 43 by setting 'resetpagenum' => '43'

$mpdf->AddPageByArray([
    'margin-left' => '15mm',
    'margin-right' => '20mm',
    'margin-top' => '25mm',
    'margin-bottom' => '15mm',
    'resetpagenum' => '43'
]);


来源:https://stackoverflow.com/questions/40471263/mpdf-start-page-numbering-from-number-10-on-the-first-sheet

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!