: This article mainly introduces php's perfect html-to-pdf conversion. if you are interested in PHP tutorials, please refer to it.
1. install wkhtmltopdf
Centos 7 installation method yum install wkhtmltopdf
If the version is earlier than 7, you need to download and install
:http:
//download.csdn.net/detail/liwei1987821/9337289
2. after the download:
# mv wkhtmltopdf-amd64 wkhtmltopdf
# mv wkhtmltopdf /usr/local/bin
Xvfb needs to be installed again
# yum install xorg-x11-server-Xvfb
3. after installation:
#xvfb-run --server-args=
"-screen 0, 1024x768x24"
wkhtmltopdf http:
//www.ifeng.com/ admin.pdf
4. if Chinese characters are garbled or blank
Open windows c: \ Windows \ fonts \ simsun. ffc and copy it to the linux server/usr/share/fonts/directory.
C: \ Windows \ fonts \ simsun \ SIMFANG. TTF.
The generated pdf will not contain garbled characters.
5. Use in php
$str
=
'xvfb-run --server-args="-screen 0, 1024x768x24" wkhtmltopdf http://www.ifeng.com/ admin.pdf > test.txt'
;
exec
(
$str
);
In order to avoid PHP suspension during execution, a redirection to a file is required.
6. I wanted
exec
In the process, the problem of long loading time is solved asynchronously. No good solution found
I tried popen and curl. please give me some advice.
The above introduces the perfect html-to-pdf implementation of php, including the content, hope to be helpful to friends who are interested in PHP tutorials.