Counting Pages

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
usamaalam
Forum Newbie
Posts: 6
Joined: Thu Oct 11, 2007 3:05 am

Counting Pages

Post by usamaalam »

Hello Everybody,

Is there a way to count total number of pages of word and pdf files with PHP?

Thanks.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Counting Pages

Post by AbraCadaver »

Lots of ways using directoryiterator or readdir, but depending upon what you need to do, I like glob():

Code: Select all

$count = count(glob('/dir/{*.pdf,*.doc}', GLOB_BRACE));
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Counting Pages

Post by josh »

Thats not what he asked
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Counting Pages

Post by AbraCadaver »

josh wrote:Thats not what he asked
Ahh, I see. That will count the total number of files, not pages within the files if that's what you wanted. :oops:
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Counting Pages

Post by josh »

usamaalam, I would look into command line Open Office. I don't know if it does what you want for sure, but it does a lot. I know for a fact I can convert doc to pdf in OO. Then I know for a fact I can use posttext imagemagick extension to convert each page to a JPG. Then I could glob and count the jpgs.

Maybe some one has a clearer solution, or maybe Open Office has a way to get the page count already. Do report back with what you find.
Post Reply