PHP reading PDF content with Xpdf usage _ PHP Tutorial

Source: Internet
Author: User
PHP reads PDF content in combination with Xpdf. 1. download the documents first. If you do not need to convert Chinese, you just need to download it can: xpdf-bin-linux-3.03.tar, if you need to convert Chinese, then you still need 1. Download
First, we should first download the documents first.
If you do not need to convert Chinese words, just need to download it can: xpdf-bin-linux-3.03.tar, if you need to convert Chinese, then you need it again: xpdf-chinese-simplified.tar

II. Installation
Now, the download is complete. we can install it.
[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/(put the downloaded file in the/lcf/xpdf directory)
[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
If you do not need to read Chinese characters, it will end up here. if you need to, we will continue later.
[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/
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)

III. function implementation
Now, all the configurations are complete, and we will start using them.
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 to Chinese, add the parameter.
$ Content = shell_exec ('/usr/local/bin/fig-layout-enc GBK'. $ filename .'-');
Of course, the English conversion is still not affected after parameters are added, so feel free to use them. 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 ');
So far, we have achieved success. The read content, how do you want to use it, and then write the code for processing.
At last, add the parameter description of totext to everyone.

The main parameters are as follows::
OPTIONS
Setting of the following options can be set with configuration file com-
Mands. These are listed in square brackets with the description of
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
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
Meta headers.
-Enc encoding-name

First, we need to describe the materials first. If you do not need to convert Chinese, just download it can: xpdf-bin-linux-3.03.tar, if you need to convert Chinese, then you still need...

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.