一.下载
首先,我们先把资料下下来先。
如果不需要转中文的话,只需要下载它就可以:xpdf-bin-linux-3.03.tar,如果需要转中文,那你就还需要它了:xpdf-chinese-simplified.tar
二.安装
现在,下载完毕了吧,我们可以进行安装了。
[root@localhost ~]# mkdir -p /lcf/upan
[root@localhost ~]# mkdir -p /lcf/cdrom
[root@localhost ~]# mkdir -p /lcf/xpdf
[root@localhost ~]# cd /lcf/upan/
[root@localhost upan]# cp xpdf/* ../xpdf/ (下载的文件放入/lcf/xpdf目录)
[root@localhost upan]# cd ../xpdf/
[root@localhost xpdf]# tar -zxvf xpdfbin-linux-3.03.tar.gz
[root@localhost xpdf]# cd xpdfbin-linux-3.03
[root@localhost xpdfbin-linux-3.03]# cat INSTALL
[root@localhost xpdfbin-linux-3.03]# cd bin32/
[root@localhost bin32]# cp ./* /usr/local/bin/
[root@localhost bin32]# cd ../doc/
[root@localhost doc]# mkdir -p /usr/local/man/man1
[root@localhost doc]# mkdir -p /usr/local/man/man5
[root@localhost doc]# cp *.1 /usr/local/man/man1
[root@localhost doc]# cp *.5 /usr/local/man/man5
如果不需要读取中文的话,到这里就可以结束了,如果需要,那我们继续往后
[root@localhost doc]# cp sample-xpdfrc /usr/local/etc/xpdfrc
[root@localhost xpdf]# cd /lcf/xpdf
[root@localhost xpdf]# tar -zxvf xpdf-chinese-simplified.tar.gz
[root@localhost xpdf]# cd xpdf-chinese-simplified
[root@localhost xpdf]# mkdir -p/usr/local/share/xpdf/chinese-simplified
[root@localhost xpdf]# cd xpdf-chinese-simplified/
[root@localhost xpdf-chinese-simplified]# cp Adobe-GB1.cidToUnicode ISO-2022-CN.unicodeMap EUC-CN.unicodeMap GBK.unicodeMap CMAP /usr/local/share/xpdf/chinese-simplified/
把chinese-simplified里面文件add-to-xpdfrc 的内容复制到/usr/local/etc/xpdfrc文件中。记得里面的路径要正确。(注意,这里面的简体中文包包括以下三种格式:ISO-2022-CN,EUC-CN,GBK ,看清楚哦,不支持UTF-8,可以先转为GBK,然后进行转义)
三.功能实现
至此,所有的配置完毕,我们要开始使用它了。
如果是简单的PDF读取,那么直接用下面的语句就OK了。
$content = shell_exec('/usr/local/bin/pdftotext '.$filename.' -');
如果需要转中文,如此这般,加上参数。
$content = shell_exec('/usr/local/bin/pdftotext -layout -enc GBK '.$filename.' -');
当然,加了参数之后依然是不影响英文的转换的,所以,放心使用吧。需要注意的是,这里转出来的是GBK编码的哦,现在网站很多用的是UTF-8,想要不显示乱码的话,需要再次转义一下哦。
$content = mb_convert_encoding($content, 'UTF-8','GBK');
至此,就大功告成了。读取出来的内容,你想如何使用,再写代码处理吧。
最后加一下pdftotext 的参数说明给大家。
主要参数如下:
OPTIONS
Many of the following options can be set with configuration file com-
mands. These are listed in square brackets with the description of the
corresponding command line option.
-f number
Specifies the first page to convert.
-l number
Specifies the last page to convert.
-layout
Maintain (as best as possible) the original physical layout of
the text. The default is to 'undo' physical layout (columns,
hyphenation, etc.) and output the text in reading order.
-fixed number
Assume fixed-pitch (or tabular) text, with the specified charac-
ter width (in points). This forces physical layout mode.
-raw Keep the text in content stream order. This is a hack which
often "undoes" column formatting, etc. Use of raw mode is no
longer recommended.
-htmlmeta
Generate a simple HTML file, including the meta information.
This simply wraps the text in <pre> and </pre> and prepends the
meta headers.
-enc encoding-name
PHP读取PDF内容配合Xpdf的使用
2020-01-20 15:05PHP教程网 PHP教程
最近领导拍脑袋想出了一个需求,要我读取PDF里面的内容,并且入库存为正文,用来搜索,需要的朋友可以了解下
延伸 · 阅读
- 2022-03-10怎样把pdf转换成excel文档格式
- 2022-03-10简单谈谈centos7中配置php
- 2022-03-08C#实现Word转为PDF的方法
- 2022-03-08C#将PPT文件转换成PDF文件
- 2022-03-08C#将Excel转成PDF的方法
- 2022-03-06Ubuntu14.04服务器环境下配置PHP7.0+Apache2+Mysql5.7的方
- PHP教程
php比较两个指定的日期的实例讲解
在本篇文章里小编给大家整理了一篇关于php如何比较两个指定的日期的相关知识点内容,有需要的朋友们可以参考下。...
- PHP教程
PHP面向对象详解(三)
这篇文章主要介绍了PHP面向对象详解(三) 的相关资料,需要的朋友可以参考下...
- PHP教程
php curl_init函数用法
使用PHP的cURL库可以简单和有效地去抓网页。你只需要运行一个脚本,然后分析一下你所抓取的网页,然后就可以以程序的方式得到你想要的数据了 ...
- PHP教程
laravel 输出最后执行sql 附:whereIn的使用方法
今天小编就为大家分享一篇laravel 输出最后执行sql 附:whereIn的使用方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...
- PHP教程
Linux平台PHP5.4设置FPM线程数量的方法
这篇文章主要介绍了Linux平台PHP5.4设置FPM线程数量的方法,较为详细的分析了Linux平台php5.4设置FPM的相关参数、功能及使用技巧,需要的朋友可以参考下...
- PHP教程
php eval函数用法 PHP中eval()函数小技巧
本函式可将字符串之中的变量值代入,通常用在处理数据库的数据上 ...
- PHP教程
CodeIgniter记录错误日志的方法全面总结
这篇文章主要介绍了CodeIgniter记录错误日志的方法,详细分析了CodeIgniter框架的文件结构与相应的功能,结合实例分析了CodeIgniter框架记录错误日志的实现技巧...
- PHP教程
PHP编程中的Session阻塞问题与解决方法分析
这篇文章主要介绍了PHP编程中的Session阻塞问题与解决方法,简单分析了php session阻塞的原理、原因与简单解决方法,需要的朋友可以参考下...