PHP获取word文档页数

{{ time }}

此方法需要一个Windows服务器, 并安装Office, 并已进行相关配置.

本方法使用COM

示例代码如下

function getTotalPage()
{
    $id = 20;

    $filenamedoc = dirname(__FILE__) . "/doc/$id.doc";

    $dd = $word = new COM("Word.Application") or die("Could not initialise Object.");
    // set it to 1 to see the MS Word window (the actual opening of the document)
    $word->Visible = 0;
    // recommend to set to 0, disables alerts like "Do you want MS Word to be the default .. etc"
    $word->DisplayAlerts = 0;
    // open the word 2007-2013 document

    $word->Documents->Open($filenamedoc);

    $docRange = $word->ActiveDocument->Content;

    echo $docRange->Information(4); //总页数

    $word->Quit(false);
}

参考文献:

https://blog.csdn.net/wang740209668/article/details/108715888