6

I used getNumPages() function to get the total number of pages in tcpdf, but I didn't get the correct output. What should I do to get the correct number?

0

2 Answers 2

14

Hi I just wanted to add for anyone reading this, that I was using getNumPages() like you in the footer and it was giving me trouble because it was showing me the number of pages inserted up to now. So I was getting 1/1, 2/2, 3/3, etc.

This is what I tried at first:

$this->getPage().'/'.$this->getNumPages()

I looked at example number 3 and used the following instead to get the correct result.

$this->getAliasNumPage().'/'.$this->getAliasNbPages()
3
  • This is a good answer - my app using if condition for manual page breaking (better) and "$this->getPage().'/'.$this->getNumPages()" return something like 1/1 2/2 ... n/n for n pages doc
    – gonatee
    Jan 17, 2017 at 10:59
  • It returns output as String. when we convert it to integer then output is zero. how to get integer typed current page number and total pages count? Kindly suggest thanks.
    – Kamlesh
    Mar 27, 2022 at 14:25
  • (int) and intval() both are not working on getAliasNumPage and getAliasNbPages functions. any suggestion?
    – Kamlesh
    Mar 27, 2022 at 14:29
0
$this->getAliasNumPage()

actually returns the string "{:ptp:}", useful for adding the total number of pages after the PDF has been created when you don't know how many pages it will have.

$this->PageNo();

returns an integer of the current page number which is what I was looking for

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.