1. Install wkhtmltopdf
centos 7 version Installation method yum install wkhtmltopdf
If the version is lower than 7, you need to download and install
Download address: http:
// download.csdn.net/detail/liwei1987821/9337289
2. After downloading:
# mv wkhtmltopdf-amd64 wkhtmltopdf
# mv wkhtmltopdf /usr/local/bin
Need to install xvfb
# yum install xorg-x11-server-Xvfb
3. After the installation is complete:
# xvfb-run --server-args=
"-screen 0, 1024x768x24"
wkhtmltopdf http:
//www.ifeng.com/ admin.pdf
4. If Chinese characters appear garbled or blank
Open windows c:Windowsfontssimsun. Copy ffc to the Linux server /usr/share/fonts/ directory
c:WindowsfontssimsunSIMFANG.TTF and copy it in the same way
Execute the generated pdf again and there will be no 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
); Direct to file
exec
I have tried popen and curl and both have problems. Please give me some advice
The above has introduced the perfect implementation of html to pdf in php, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.