Number of pages in PHP MS Word files

Actually, I am trying to count pages from ms word file, I am using this php script, but without showing me the exact result, and the script is not working so fast. Can anyone help me get a better script.

$word = new COM("word.application"); if (!$word) { echo ("Could not initialise MS Word object.\n"); exit(1); } $word->Documents->Open(realpath("d:\\Test\\t.docx")); $pages = $word->ActiveDocument->BuiltInDocumentProperties(14); echo "Number of pages: " . $pages->value; $word->ActiveDocument->Close(false); $word->Quit(); $word = null; unset($word); 
+4
source share
1 answer

try it

 $filename = "PATH"; $word = new COM("Word.Application"); $word->visible = true; $word->Documents->Open($filename); $wdStatisticPages = 2; // Value that corresponds to the Page count in the Statistics $word->ActiveDocument->ComputeStatistics($wdStatisticPages); echo "Total Page(s) : ". $word->ActiveDocument->ComputeStatistics($wdStatisticPages); $word->ActiveDocument->PrintOut(); $word->ActiveDocument->Close(); $word->Quit(); 

Basically, call the ComputeStatistics() method with the correct value as the parameter.

+2
source

All Articles