PHP - Get number of pages in a Word document

后端 未结 5 1945
终归单人心
终归单人心 2020-12-10 23:24

Is there a way to count number of pages using PHP for existing Word documents?

I appreciate for the help.

Thanks

相关标签:
5条回答
  • 2020-12-11 00:04

    Have a look at PhpWord from microsoft codeplex ... "http://phpword.codeplex.com/

    It will allow you to open and read the word formatted file in PHP and do whatever processing you require.

    0 讨论(0)
  • 2020-12-11 00:07

    To get meta data properties of doc,docx,ppt and pptx like number of pages, number of slides from PHP i followed the following process and it worked liked charm and iam so happy, below is the process i followed , hope it helps someone

    Download and configure Apache Tika.
    

    once its done you could try executing the following commadn it will give all the meta data about your file

    java -jar tika-app-1.5.jar -m test.docx
    java -jar tika-app-1.5.jar -m test.doc
    java -jar tika-app-1.5.jar -m test.pptx
    java -jar tika-app-1.5.jar -m test.ppt
    

    once tested you can execute this comman in PHP script. Thanks.

    0 讨论(0)
  • 2020-12-11 00:15

    You will need to find an appropriate 3rd party library (or write your own) if you are using a Windows server you could look into using a COM interface.

    Here is how you would do it with COM... (but I haven't tested it yet)

       $wdStatisticPages = 2;
       $word = new COM("word.application") or die("Unable to instantiate Word");
       $word->Document->Open( "path/to/file.doc" );
       $num_pages = $word->ActiveDocument->ComputeStatistics( $wdStatisticPages );
    
    0 讨论(0)
  • 2020-12-11 00:18

    You need a library that can read Word docs. I recommend: http://www.phplivedocx.org/ You'll also need the Zend Framework: http://framework.zend.com/

    I'm sure there are many more libraries available, but I find this to be the most current and well maintained.

    0 讨论(0)
  • 2020-12-11 00:30

    I think that this is difficult to do reliably, because the number of pages in a Word document can depend on what printer driver is installed in the Word application used to view it.

    0 讨论(0)
提交回复
热议问题