最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

PHP讀取PDF內(nèi)容配合Xpdf的使用

 更新時(shí)間:2012年11月24日 14:20:27   作者:  
最近領(lǐng)導(dǎo)拍腦袋想出了一個(gè)需求,要我讀取PDF里面的內(nèi)容,并且入庫存為正文,用來搜索,需要的朋友可以了解下

一.下載
首先,我們先把資料下下來先。
如果不需要轉(zhuǎn)中文的話,只需要下載它就可以:xpdf-bin-linux-3.03.tar,如果需要轉(zhuǎn)中文,那你就還需要它了:xpdf-chinese-simplified.tar

二.安裝
現(xiàn)在,下載完畢了吧,我們可以進(jìn)行安裝了。
[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
如果不需要讀取中文的話,到這里就可以結(jié)束了,如果需要,那我們繼續(xù)往后
[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 的內(nèi)容復(fù)制到/usr/local/etc/xpdfrc文件中。記得里面的路徑要正確。(注意,這里面的簡體中文包包括以下三種格式:ISO-2022-CN,EUC-CN,GBK ,看清楚哦,不支持UTF-8,可以先轉(zhuǎn)為GBK,然后進(jìn)行轉(zhuǎn)義)

三.功能實(shí)現(xiàn)
至此,所有的配置完畢,我們要開始使用它了。
如果是簡單的PDF讀取,那么直接用下面的語句就OK了。
$content = shell_exec('/usr/local/bin/pdftotext '.$filename.' -');
如果需要轉(zhuǎn)中文,如此這般,加上參數(shù)。
$content = shell_exec('/usr/local/bin/pdftotext -layout -enc GBK '.$filename.' -');
當(dāng)然,加了參數(shù)之后依然是不影響英文的轉(zhuǎn)換的,所以,放心使用吧。需要注意的是,這里轉(zhuǎn)出來的是GBK編碼的哦,現(xiàn)在網(wǎng)站很多用的是UTF-8,想要不顯示亂碼的話,需要再次轉(zhuǎn)義一下哦。
$content = mb_convert_encoding($content, 'UTF-8','GBK');
至此,就大功告成了。讀取出來的內(nèi)容,你想如何使用,再寫代碼處理吧。
最后加一下pdftotext 的參數(shù)說明給大家。

主要參數(shù)如下:
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

相關(guān)文章

  • php實(shí)現(xiàn)圖形顯示Ip地址的代碼及注釋

    php實(shí)現(xiàn)圖形顯示Ip地址的代碼及注釋

    這篇文章主要介紹了php實(shí)現(xiàn)圖形顯示Ip地址,有需要的朋友可以參考一下
    2014-01-01
  • Laravel框架中緩存的使用方法分析

    Laravel框架中緩存的使用方法分析

    這篇文章主要介紹了Laravel框架中緩存的使用方法,結(jié)合具體實(shí)例形式分析了Laravel框架中緩存的常用方法、操作步驟及相關(guān)使用操作技巧,需要的朋友可以參考下
    2019-09-09
  • 利用php-cli和任務(wù)計(jì)劃實(shí)現(xiàn)訂單同步功能的方法

    利用php-cli和任務(wù)計(jì)劃實(shí)現(xiàn)訂單同步功能的方法

    下面小編就為大家?guī)硪黄胮hp-cli和任務(wù)計(jì)劃實(shí)現(xiàn)訂單同步功能的方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-05-05
  • Laravel框架使用Seeder實(shí)現(xiàn)自動填充數(shù)據(jù)功能

    Laravel框架使用Seeder實(shí)現(xiàn)自動填充數(shù)據(jù)功能

    這篇文章主要介紹了Laravel框架使用Seeder實(shí)現(xiàn)自動填充數(shù)據(jù)功能,結(jié)合實(shí)例形式分析了Laravel基于Seeder類實(shí)現(xiàn)自動填充數(shù)據(jù)的相關(guān)操作技巧與注意事項(xiàng),需要的朋友可以參考下
    2018-06-06
  • thinkPHP5框架分頁樣式類完整示例

    thinkPHP5框架分頁樣式類完整示例

    這篇文章主要介紹了thinkPHP5框架分頁樣式類,結(jié)合完整實(shí)例形式分析了thinkPHP5帶css樣式控制的分頁類定義與簡單使用方法,需要的朋友可以參考下
    2018-09-09
  • PHP生成帶有雪花背景的驗(yàn)證碼

    PHP生成帶有雪花背景的驗(yàn)證碼

    晚看到了chianren上的驗(yàn)證碼效果,就考慮了一下,用PHP的GD庫完成了類似功能 先成生背景,再把生成的驗(yàn)證碼放上去
    2008-09-09
  • 最新評論

    绥芬河市| 凉山| 余庆县| 阿瓦提县| 应城市| 祁门县| 鹰潭市| 南涧| 库车县| 晋宁县| 贵港市| 额济纳旗| 库车县| 逊克县| 佛坪县| 上饶县| 托克托县| 鹤壁市| 双柏县| 桐梓县| 阿坝| 会同县| 沛县| 屯门区| 邵阳县| 金寨县| 安图县| 朝阳区| 云梦县| 定日县| 兖州市| 天峨县| 麻栗坡县| 柳林县| 信丰县| 乐清市| 曲沃县| 台东县| 罗城| 广安市| 江永县|