Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the total number of pages in MPDF?

Tags:

php

pdf

mpdf

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
like image 985
sravis Avatar asked Jun 13 '13 09:06

sravis


People also ask

How do I count the number of pages in a PDF in PHP?

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.

How do I change page size in mPDF?

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.

What is mPDF format?

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.


1 Answers

According to the official documentation:

$mpdf=new mPDF();
$mpdf->setFooter("Page {PAGENO} of {nb}");
like image 53
sr9yar Avatar answered Oct 01 '22 08:10

sr9yar