2011-03-03 174 views
1

可能重复:
Read pdf files with php阅读PDF文件

你可以阅读使用PHP代码的PDF文件?

+0

您想如何处理PDF?您是否尝试从中读取文本数据,或只是将几个PDF文件合并在一起? – 2011-03-03 12:32:24

+0

请求之前请使用搜索功能。这已被回答无数次:http://stackoverflow.com/search?q=read+pdf+files+php – Gordon 2011-03-03 12:41:07

回答

2

是的,可以。无论是安装command line script that can convert PDFs to text和PHP

$content = shell_exec('/usr/local/bin/pdftotext '.$filename.' -'); //dash at the end to output content 

source)执行此

...或写a PHP function like this

+0

为使用(shell_exec)上面的代码给你,是否有任何支持文件是需要或这个单一的代码将PDF转换为文本文件.. – 2011-03-03 12:42:39

+1

您需要安装我在第一个链接中提到的命令行脚本。 – slhck 2011-03-03 12:44:04

+0

哦非常感谢你的工作正常...有没有其他的方式或代码来读取PHP文件.. – 2011-03-03 12:47:27

3

要阅读PDF文件,您需要安装XPDF(http://www.foolabs.com/xpdf/about.html)软件包,其中包含“pdftotext”。安装XPDF/pdftotext后,运行以下PHP语句以获取PDF文本:

$content = shell_exec('/usr/local/bin/pdftotext '.$filename.' -'); //dash at the end to output content 
+0

我的答案完全重复:p – slhck 2011-03-03 12:44:25

+1

slhck:对不起,请参阅http://stackoverflow.com/questions/5177726/is-there-any-library-available-in-php-to-convert-pdf-file-to-html/5177817#5177817 – Efazati 2011-03-03 12:45:46

+1

哦,我明白了......可以预料到这个问题以前就被问过了。 – slhck 2011-03-03 12:46:55