PHP获取word文档页数

// 获取word文档页码(不好使,不准确)
function getTotalPage($filename){
    $zip = new \ZipArchive();
    if($zip->open($filename) === true) {
        if(($index = $zip->locateName('docProps/app.xml')) !== false) {
            $data = $zip->getFromIndex($index);
            $zip->close();
            $xml = new \SimpleXMLElement($data);
            return $xml->Pages;
        }
        $zip->close();
    }
    return false;
}

// 获取word文档的页码 准确,但是速度太慢
function getWordPageNum($filename){
    $word = new \COM("Word.Application",null,CP_UTF8) or die("Could not initialise Object.");
    $word->Documents->Open($filename);
    $docRange = $word->ActiveDocument->Content;
    $num = $docRange->Information(4); //总页数
    $word->Quit(false);
    return $num;
}
点赞

发表回复

电子邮件地址不会被公开。必填项已用 * 标注