【发布时间】:2011-05-27 03:45:05
【问题描述】:
嗨,
我有大量的 pdf 文档。我想使用 php 脚本来阅读它。我搜索了很多,但每个人都在创建 pdf 文件。在这里,我不想创建 pdf 文件,但我想阅读它。有什么办法可以用php来读吗?
-阿伦
【问题讨论】:
-
定义“阅读”——你想提取文本内容吗?图像呢?
标签: php pdf filereader
嗨,
我有大量的 pdf 文档。我想使用 php 脚本来阅读它。我搜索了很多,但每个人都在创建 pdf 文件。在这里,我不想创建 pdf 文件,但我想阅读它。有什么办法可以用php来读吗?
-阿伦
【问题讨论】:
标签: php pdf filereader
您可以使用命令行实用程序(如 Pdftotext)轻松读取 PDF 文件的内容,您可以通过 exec 调用该实用程序。
这是我的意思的一个例子,实际使用system
system("pdftotext your.pdf /tmp/txtfile.txt");
$text = file_get_contents("/tmp/txtfile.txt");
编辑
不知道破折号语法 - 这更好:
$content = shell_exec('pdftotext your.pdf -');
不过,这确实需要在您的服务器上安装 pdftotext。在 CentOS 服务器上,这将是:
yum install xpdf
【讨论】:
要仅从 PDF 文件中获取文本,请尝试以下操作:
- http://davidwalsh.name/read-pdf-doc-file-php
- http://www.webcheatsheet.com/php/reading_clean_text_from_pdf.php(更深入)
有关更重量级的解决方案,请查看:
- http://www.setasign.de/products/pdf-php-solutions/fpdi/
【讨论】: