PHP MS Word文件页数 [英] PHP MS Word files page count

查看:124
本文介绍了PHP MS Word文件页数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上,我正在尝试从ms字文件中计算页面数,我正在使用此php脚本,但是,没有向我显示确切的结果,并且该脚本的运行速度也不太快.谁能帮助我获得更好的脚本.

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

推荐答案

尝试一下

$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()方法.

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

这篇关于PHP MS Word文件页数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆