搜尋
首頁後端開發php教程PHP读取PDF内容(LINUX下XPDF的配置和使用)_PHP教程

PHP读取PDF内容(LINUX下XPDF的配置和使用)_PHP教程

Jul 14, 2016 am 10:07 AM
linuxpdfphp使用內容我們讀取資料配置首先

  一.下载


        首先,我们先把资料下下来先。 
        如果不需要转中文的话,只需要下载它就可以: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

 and 
and prepends the
meta headers.

-enc encoding-name


 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/477900.htmlTechArticle一.下载 首先,我们先把资料下下来先。 如果不需要转中文的话,只需要下载它就可以:xpdf-bin-linux-3.03.tar,如果需要转中文,那你就还需...
陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
解釋負載平衡如何影響會話管理以及如何解決。解釋負載平衡如何影響會話管理以及如何解決。Apr 29, 2025 am 12:42 AM

負載均衡會影響會話管理,但可以通過會話複製、會話粘性和集中式會話存儲解決。 1.會話複製在服務器間複製會話數據。 2.會話粘性將用戶請求定向到同一服務器。 3.集中式會話存儲使用獨立服務器如Redis存儲會話數據,確保數據共享。

說明會話鎖定的概念。說明會話鎖定的概念。Apr 29, 2025 am 12:39 AM

Sessionlockingisatechniqueusedtoensureauser'ssessionremainsexclusivetooneuseratatime.Itiscrucialforpreventingdatacorruptionandsecuritybreachesinmulti-userapplications.Sessionlockingisimplementedusingserver-sidelockingmechanisms,suchasReentrantLockinJ

有其他PHP會議的選擇嗎?有其他PHP會議的選擇嗎?Apr 29, 2025 am 12:36 AM

PHP會話的替代方案包括Cookies、Token-basedAuthentication、Database-basedSessions和Redis/Memcached。 1.Cookies通過在客戶端存儲數據來管理會話,簡單但安全性低。 2.Token-basedAuthentication使用令牌驗證用戶,安全性高但需額外邏輯。 3.Database-basedSessions將數據存儲在數據庫中,擴展性好但可能影響性能。 4.Redis/Memcached使用分佈式緩存提高性能和擴展性,但需額外配

在PHP的上下文中定義'會話劫持”一詞。在PHP的上下文中定義'會話劫持”一詞。Apr 29, 2025 am 12:33 AM

Sessionhijacking是指攻擊者通過獲取用戶的sessionID來冒充用戶。防範方法包括:1)使用HTTPS加密通信;2)驗證sessionID的來源;3)使用安全的sessionID生成算法;4)定期更新sessionID。

PHP的完整形式是什麼?PHP的完整形式是什麼?Apr 28, 2025 pm 04:58 PM

文章討論了PHP,詳細介紹了其完整形式,在We​​b開發中的主要用途,與Python和Java的比較以及對初學者的學習便利性。

PHP如何處理形式數據?PHP如何處理形式數據?Apr 28, 2025 pm 04:57 PM

PHP使用$ \ _ post和$ \ _獲取超級全局的php處理數據,並通過驗證,消毒和安全數據庫交互確保安全性。

PHP和ASP.NET有什麼區別?PHP和ASP.NET有什麼區別?Apr 28, 2025 pm 04:56 PM

本文比較了PHP和ASP.NET,重點是它們對大規模Web應用程序,性能差異和安全功能的適用性。兩者對於大型項目都是可行的,但是PHP是開源和無關的,而ASP.NET,

PHP是對病例敏感的語言嗎?PHP是對病例敏感的語言嗎?Apr 28, 2025 pm 04:55 PM

PHP的情況敏感性各不相同:功能不敏感,而變量和類是敏感的。最佳實踐包括一致的命名和使用對案例不敏感的功能進行比較。

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

Dreamweaver Mac版

Dreamweaver Mac版

視覺化網頁開發工具

mPDF

mPDF

mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

SublimeText3 Linux新版

SublimeText3 Linux新版

SublimeText3 Linux最新版

Atom編輯器mac版下載

Atom編輯器mac版下載

最受歡迎的的開源編輯器

PhpStorm Mac 版本

PhpStorm Mac 版本

最新(2018.2.1 )專業的PHP整合開發工具