PHP-获取Word文档中的页数

发布于 2024-07-29 11:07:49 字数 68 浏览 3 评论 0原文

有没有办法使用 PHP 计算现有 Word 文档的页数?

我很感激你的帮助。

谢谢

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

I appreciate for the help.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

亣腦蒛氧 2024-08-05 11:07:49

您需要一个可以读取 Word 文档的库。 我建议:http://www.phplivedocx.org/ 您还需要 Zend 框架:< a href="http://framework.zend.com/" rel="nofollow noreferrer">http://framework.zend.com/

我确信还有更多可用的库,但我发现这是最新且维护良好的。

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.

一萌ing 2024-08-05 11:07:49

如果您使用的是 Windows 服务器,则需要找到合适的第 3 方库(或编写您自己的库),您可以考虑使用 COM 接口。

这是使用 COM 的方法...(但我还没有测试过)

   $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 );

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 );
习ぎ惯性依靠 2024-08-05 11:07:49

为了从 PHP 获取 doc、docx、ppt 和 pptx 的元数据属性(例如页数、幻灯片数),我遵循了以下过程,它的工作很有趣,我很高兴,下面是我遵循的过程,希望它能帮助某人

Download and configure Apache Tika.

一次完成后,您可以尝试执行以下命令,它会提供有关您的文件的所有元数据,

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

一旦测试,您可以在 PHP 脚本 中执行此命令。 谢谢。

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.

时光是把杀猪刀 2024-08-05 11:07:49

我认为这很难可靠地做到,因为 Word 文档中的页数可能取决于用于查看该文档的 Word 应用程序中安装的打印机驱动程序。

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.

物价感观 2024-08-05 11:07:49

看看 microsoft codeplex 的 PhpWord ...“http://phpword.codeplex.com/

它将允许您在 PHP 中打开和读取 word 格式的文件,并执行您需要的任何处理。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文