This is an archived forum post. The information may be outdated. Contact us if you have any questions.

getPageCount()

lfreke wrote on 2019-02-06:
Hi,

The getPageCount() function in the PDF to PDF API doesn't appear to function correctly on PDFs generated by the HTML to PDF API and simply outputs 0

I've tried using the PHP v4.3.5 and v4.4.2 API's
support wrote on 2019-02-06:
The getPageCount() function returns correct number of pages after a successful conversion.

Please send your PHP code using Pdfcrowd API to support@pdfcrowd.com
lfreke wrote on 2019-02-06:
The function seems to work in different ways depending on the document being added. My experience with it has been as below. The conversion doesn't seem to be necessary in the first instance, whereas it is in the second.

The issue with this is that getting the number of pages before the conversion is useful when trying to ensure that duplex printing occurs correctly. If there's an odd number of pages, a blank page PDF can be added to effectively pad the document

$client = new \Pdfcrowd\PdfToPdfClient('', '');
$client->addPdfFile('/path/to/adobe-created/pdf');
echo $client->getPageCount(); // Returns correct number

/****************/

$client = new \Pdfcrowd\HtmlToPdfClient('', '');
$client->convertURLToFile('URL', '/path/to/generated/pdf');

$client = new \Pdfcrowd\PdfToPdfClient('', '');
$client->addPdfFile('/path/to/generated/pdf');
echo $client->getPageCount(); // Returns 0
support wrote on 2019-02-06:
It's strange. The first test should return 0 too because there was no conversion executed. Try to add $client->convertToFile("output.pdf"); right before echo $client->getPageCount();
e.g.

$client = new \Pdfcrowd\PdfToPdfClient('', '');
$client->addPdfFile('/path/to/adobe-created/pdf');
$client->convertToFile("output.pdf");
echo $client->getPageCount(); // Returns correct number