2

** this code working .docx format document ** ** but my need .doc format document count pages number in php **

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;
}
Dipu Raj
  • 1,784
  • 4
  • 29
  • 37
Ashikur Rahman
  • 39
  • 1
  • 1
  • 5

2 Answers2

0

Follow these steps to get page count of .doc document.

Step 1: Make sure php_com_dotnet.dll on your php.ini file. If you can not find that, you have to add that first(you don't want to download any .dll, just add following line), After you add this extension restart Apache server.

extension=php_com_dotnet.dll

Step 2: Run this answer, PHP MS Word files page count. When you add the $filename, add that this way,

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

Step 3: Before you running the script. Make sure that word document is closed.

Community
  • 1
  • 1
Gayan
  • 2,845
  • 7
  • 33
  • 60
0

I have done many implementations on docx pdf and xlsx using java. NOt sure about PHP But i will help you with one the description which will be help full

Try this way:

**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.

Thank you ..

KishanCS
  • 1,357
  • 1
  • 19
  • 38