PHP perfect for HTML to PDF

Source: Internet
Author: User
Tags wkhtmltopdf
1. 安装 wkhtmltopdf

centos 7版本 安装方法 yum install wkhtmltopdf

如果版本低于7则需要下载安装

下载地址:http://download.csdn.net/detail/liwei1987821/9337289

2. 下载后 :

# mv wkhtmltopdf-amd64 wkhtmltopdf

# mv wkhtmltopdf /usr/local/bin

需要再安装xvfb

# yum install xorg-x11-server-Xvfb

3. 安装完成后:

#xvfb-run --server-args="-screen 0, 1024x768x24"wkhtmltopdf http://www.ifeng.com/ admin.pdf

4. 如果中文出现乱码或空白

打开windows c:\Windows\fonts\simsun.ffc拷贝到linux服务 器/usr/share/fonts/目录下

c:\Windows\fonts\simsun\SIMFANG.TTF 一样拷贝进去

再执行生成的pdf就不会出现乱码了

5. 在 php中的使用

$str='xvfb-run --server-args="-screen 0, 1024x768x24" wkhtmltopdf http://www.ifeng.com/ admin.pdf > test.txt';

exec($str);

为了避免执行过程中PHP挂起 需要出重定向到文件

6. 本来想在exec过程中使用异步 解决loading时间长的问题 。一直没有找到好的解决方案

试过popen 和curl 都有问题 求大神指点

The above describes the PHP perfect to achieve HTML to PDF, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.