Is there a way to count number of pages using PHP for existing Word documents?
I appreciate for the help.
Thanks
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 );
To get meta data properties of doc,docx,ppt and pptx like number of pages, number of slides from PHP i followed the following process and it worked liked charm and iam so happy, below is the process i followed , hope it helps someone
Download and configure Apache Tika.
once its done you could try executing the following commadn it will give all the meta data about your file
java -jar tika-app-1.5.jar -m test.docx
java -jar tika-app-1.5.jar -m test.doc
java -jar tika-app-1.5.jar -m test.pptx
java -jar tika-app-1.5.jar -m test.ppt
once tested you can execute this comman in PHP script
. Thanks.
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.
Have a look at PhpWord from microsoft codeplex ... "http://phpword.codeplex.com/
It will allow you to open and read the word formatted file in PHP and do whatever processing you require.