2016-11-27 19 views
2

**這段代碼工作.docx格式文件** **但我需要.doc格式文件計數頁面number in php **如何在.doc文件中得到沒有頁面的php,下面的代碼適用於.docx而不是.doc

function CountPagesDocx($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; 
} 
+0

你檢查HTTP://計算器.com/questions/23561719/find-out-page-numbers-of-pdf-docx-doc-ppt-pptx-files-with-php – user3099298

+0

感謝您的鏈接。但是你提供的鏈接並沒有解決我的.doc文件問題。 –

回答

0

請按照以下步驟獲取.doc文件的頁數。

步驟1:確保您的php.ini文件中有php_com_dotnet.dll。如果找不到,請首先添加(不想下載任何.dll,只需添加以下行),添加此擴展程序後重新啓動Apache服務器

extension=php_com_dotnet.dll 

第2步:運行這個答案,PHP MS Word files page count。當您添加$filename,添加這種方式,

$filename = "C:\\xampp\htdocs\project\myfile.doc"; 

第3步:運行腳本之前。確保word文檔已關閉。

0

我已經使用java在docx pdf和xlsx上完成了許多實現。 不知道PHP 但我會幫你一個將要幫助全

嘗試這樣的描述:

**For docx** 
you can find the total page numbers in docProps/app.xml 
inside: 
<Pages>5</Pages> 

**For doc** 
Open file in text mode and find this key 
PAGE \* MERGEFORMAT 
next to it you will find DC 4 NAK 
so now it is understood that 4 is the total number of pages in doc. 

謝謝。

+0

有很多內建的方法可以實現這一點,但這很簡單。 –

相關問題