【问题标题】:Read pdf files using php [duplicate]使用php读取pdf文件[重复]
【发布时间】:2011-05-27 03:45:05
【问题描述】:

可能重复:
Read pdf files with php

嗨,

我有大量的 pdf 文档。我想使用 php 脚本来阅读它。我搜索了很多,但每个人都在创建 pdf 文件。在这里,我不想创建 pdf 文件,但我想阅读它。有什么办法可以用php来读吗?

-阿伦

【问题讨论】:

标签: php pdf filereader


【解决方案1】:

您可以使用命令行实用程序(如 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

【讨论】:

  • 感谢 seegee 的快速回复。但是你能说得更清楚吗?通过 exec 方式调用?我不能使用 php 文件调用它? P
  • @user 请先说明你需要什么。
  • 如何安装pdftotext?去哪里买?
  • 我已经下载了pdftotext。现在很困惑在哪里安装它。我在 Windows 机器上使用 wamp 服务器。
  • 完成,它的工作。我在我的系统中复制了 pdftotext 并提供了 pdftotext.exe 的完整路径,它运行良好。感谢所有回复此主题的人,尤其是 seegee。
【解决方案2】:

要仅从 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/

【讨论】:

    猜你喜欢
    • 2011-07-08
    • 2011-09-10
    • 1970-01-01
    • 2011-07-24
    • 2011-08-22
    • 2010-11-03
    • 2015-12-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多