This topic is locked

How to count number of pages in attached PDF file?

3/7/2016 5:18:11 PM
PHPRunner General questions
B
bussb author

Hello all...I am using PHPRunner for storing PDF files. For billing purposes, I would like to use a PHP function in the BeforeRecordUpdated event in my Edit form to count how many pages are in the attached PDF file.
The MySQL table, named tblRecords, has an integer field to store the page count for each record, named Page_Count. The attachment file information is in table field "File" like $values["File"]
Some web research leads me to the following PHP code to count the number of pages in a PDF file:

<?php
$document = new Imagick('2_pager.pdf');
var_dump($document->getNumberImages()); //returns 2
?>


Can someone assist me with the PHPRunner event code to accomplish this? Thank you!

Admin 3/8/2016

This is definitely possible. The actual code depends on how do you store file names in the database (regular vs basic upload) and also where exactly files are uploaded on the web server. In my understanding for this code to work you need to specify a full path to PDF file.
If you use basic upload:

$document = new Imagick('path to upload folder'.$values["filename field"]);