Php uses Xpdf to read PDF content

Source: Internet
Author: User
Php uses Xpdf to read PDF content

  1. [Root @ localhost ~] # Mkdir-p/lcf/upan
  2. [Root @ localhost ~] # Mkdir-p/lcf/cdrom
  3. [Root @ localhost ~] # Mkdir-p/lcf/xpdf
  4. [Root @ localhost ~] # Cd/lcf/upan/
  5. [Root @ localhost upan] # cp xpdf/* ../xpdf/(put the downloaded file in the/lcf/xpdf directory)
  6. [Root @ localhost upan] # cd ../xpdf/
  7. [Root @ localhost xpdf] # tar-zxvf xpdfbin-linux-3.03.tar.gz
  8. [Root @ localhost xpdf] # cd xpdfbin-linux-3.03
  9. [Root @ localhost xpdfbin-linux-3.03] # cat INSTALL
  10. [Root @ localhost xpdfbin-linux-3.03] # cd bin32/
  11. [Root @ localhost bin32] # cp./*/usr/local/bin/
  12. [Root @ localhost bin32] # cd ../doc/
  13. [Root @ localhost doc] # mkdir-p/usr/local/man/man1
  14. [Root @ localhost doc] # mkdir-p/usr/local/man/man5
  15. [Root @ localhost doc] # cp *. 1/usr/local/man/man1
  16. [Root @ localhost doc] # cp *. 5/usr/local/man/man5

If you do not need to read Chinese characters, it will end up here. if you need to, we will continue later.

  1. [Root @ localhost doc] # cp sample-xpdfrc/usr/local/etc/xpdfrc
  2. [Root @ localhost xpdf] # cd/lcf/xpdf
  3. [Root @ localhost xpdf] # tar-zxvf xpdf-chinese-simplified.tar.gz
  4. [Root @ localhost xpdf] # cd xpdf-chinese-simplified
  5. [Root @ localhost xpdf] # mkdir-p/usr/local/share/xpdf/chinese-simplified
  6. [Root @ localhost xpdf] # cd xpdf-chinese-simplified/
  7. [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/

Copy the add-to-xpdfrc file in the chinese-simplified file to the/usr/local/etc/xpdfrc file. Remember that the path is correct. (Note, here the simplified Chinese package includes the following three formats: ISO-2022-CN, EUC-CN, GBK, see clearly Oh, does not support UTF-8, you can first convert to GBK, then escape)

3. now that the function is implemented, all configurations are complete and we will start to use it. If it is a simple PDF reading, you can use the following statement directly. $ Content = shell_exec ('/usr/local/bin/plain totext'. $ filename.'-'); if you want to convert Chinese characters, add a parameter. $ Content = shell_exec ('/usr/local/bin/fig-layout-enc GBK '. $ filename. '-'); of course, after adding a parameter, the English conversion is still not affected, so feel free to use it. It should be noted that the transfer out here is GBK encoding Oh, now many websites use UTF-8, do not display garbled characters, you need to escape again. $ Content = mb_convert_encoding ($ content, 'utf-8', 'gbk'); the read content can be processed by writing code. Optional totext: optionspointer of the following options can be set with configuration file com-mands. these are listed in square brackets with the description of thecorresponding command line option. -f numberSpecifies the first page to convert. -l numberSpecifies the last page to convert. -layoutMaintain (as best as possible) the original physical layout ofthe text. the default is to 'undo 'physical layout (columns, hyphenation, etc .) and output the text in reading order. -fixed numberAssume 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 whichoften "undoes" column formatting, etc. use of raw mode is nolonger recommended. -htmlmetaGenerate a simple HTML file, including the meta information. this simply wraps the text in

 and 
And prepends themeta headers.-enc encoding-name

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.