Question

I have some HTML using which I am printing a PDF, I would like to get the count of total pages the PDF will produce in a PHP Variable.

$html2pdf = new HTML2PDF('P', 'A4');
$html2pdf->writeHTML($html, false);
$html2pdf->Output('myfile.pdf');

I would like to do something like..

$totalpages = $html2pdf->getTotalPageCount(); //should return total pages the myfile.pdf      would produce.
Was it helpful?

Solution

I've used html2pdf myself and couldn't find such a feature either. However, you can use the well-known ImageMagick library after generating your PDF to retrieve the number of pages:

$im = new Imagick();
$im->pingImage('generated.pdf');
echo $im->getNumberImages();

Has helped me, hope you can use that too.

OTHER TIPS

You can add your own method to the class that returns the number of pages. This is what I did.

public function getTotalPages() { return $this->_page; }

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top