15

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
dda
  • 6,030
  • 2
  • 25
  • 34
sravis
  • 3,562
  • 6
  • 36
  • 73

3 Answers3

30

According to the official documentation:

$mpdf=new mPDF();
$mpdf->setFooter("Page {PAGENO} of {nb}");
sr9yar
  • 4,850
  • 5
  • 53
  • 59
  • Here is a working link to all [replaceable aliases](https://mpdf.github.io/what-else-can-i-do/replaceable-aliases.html). – AbcAeffchen Nov 06 '18 at 06:17
9

you can use {nb} it gives you total number of pages in mpdf

Newton
  • 91
  • 1
  • 2
  • can we get total number of pages using {nb} in pdf body instead of header/footer? i need to display total pages count in pdf content. – ÛmÄîr MÄlîk Aug 22 '17 at 08:16
  • @ÛmÄîrMÄlîk You got anything for this mate? – Deepak Singh Jul 11 '18 at 07:40
  • @DeepakSingh looks like `{nb}` was replaced in the pdf bode before mPDF 6.0, but now it only works in header/footer. See [the documentation](https://mpdf.github.io/what-else-can-i-do/replaceable-aliases.html) for details. – AbcAeffchen Nov 06 '18 at 06:19
  • @ÛmÄîr-MÄlîk it works great in mpdf 7.x with simply {nb} in html page I use for header of page. – Meloman Mar 23 '22 at 14:34
0

I use the following in my html header template :

{PAGENO}/{nb}

For example,on 1st of total of 3 pages, the result will be :

1/3

So, you can write it wherever you want in your HTML code like header, footer, body...

Meloman
  • 3,558
  • 3
  • 41
  • 51