Home > Backend Development > PHP Tutorial > PHP perfectly realizes converting html to pdf

PHP perfectly realizes converting html to pdf

WBOY
Release: 2016-07-29 09:10:43
Original
4059 people have browsed it

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

6. I originally wanted to use asynchronous in the

exec

process to solve the problem of long loading time. I have never found a good solution

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.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template