PHP MS Word文件页数统计

4

实际上我正在尝试从一个ms word文件中计算页面数,我正在使用这个php脚本,但是它没有给我准确的结果并且速度也不够快。有人能帮我写一个更好的脚本吗?

$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);
1个回答

2

试试这个

$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();

基本上,将正确的值作为参数调用ComputeStatistics()方法。


我不知道为什么,但对我来说它不起作用。 我以前尝试过它。你有其他的建议吗? - Minhaj Hasan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接