Php perfectly implements conversion from html to pdf

Source: Internet
Author: User
Tags wkhtmltopdf
: 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 wantedexecIn 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.

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.