I'm using PHP MPDF to create PDF files. At the footer I'm able to print the current page number using
{PAGENO}
But how do I get the total number of pages in the PDF file? So that in the footer I can print like:
Page (Current Page) of (Total number of pages)
Page 1 of 6
It does not use any PHP library for performing this task. The following line of code can be used. $pageCount = (new TCPDI())->setSourceData((string)file_get_contents($fileName)); Method 3: Using pdfinfo: For Linux users, there is a faster way to count the number of pages in a pdf document than “identity” function.
When declaring an instance of \Mpdf\Mpdf class, you can specify the (default) page size and orientation for the document. The margins and orientation can be redefined throughout the document whenever you add a new page using AddPage() or <pagebreak>. It can also be set by CSS using @page.
mPDF is a PHP library which generates PDF files from UTF-8 encoded HTML. It is based on FPDF and HTML2FPDF with a number of enhancements. The original author, Ian Back, wrote mPDF to output PDF files 'on-the-fly' from his website, handling different languages.
According to the official documentation:
$mpdf=new mPDF();
$mpdf->setFooter("Page {PAGENO} of {nb}");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With