Is there a way to count number of pages using PHP for existing Word documents?
I appreciate for the help.
Thanks
Is there a way to count number of pages using PHP for existing Word documents?
I appreciate for the help.
Thanks
Hi Cory. You need a library that can read Word docs. I recommend: http://www.phplivedocx.org/ You'll also need the Zend Framework: http://framework.zend.com/
I'm sure there are many more libraries available, but I find this to be the most current and well maintained.
You will need to find an appropriate 3rd party library (or write your own) if you are using a Windows server you could look into using a COM interface.
Here is how you would do it with COM... (but I haven't tested it yet)
$wdStatisticPages = 2;
$word = new COM("word.application") or die("Unable to instantiate Word");
$word->Document->Open( "path/to/file.doc" );
$num_pages = $word->ActiveDocument->ComputeStatistics( $wdStatisticPages );
I think that this is difficult to do reliably, because the number of pages in a Word document can depend on what printer driver is installed in the Word application used to view it.