4

Actually i am trying to count the pages from a ms word file, i am using this php script, But, not showing me the exact result and the script is not so fast. Can anyone help me to 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);
Sumit Bijvani
  • 8,154
  • 17
  • 50
  • 82

1 Answers1

2

try this

$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.

Sumit Bijvani
  • 8,154
  • 17
  • 50
  • 82