PHP implements the html pdf file Generation Program

Source: Internet
Author: User
Tags wkhtmltopdf

This article introduces how to use HTML2FPDF and wkhtmltoimage in linux to directly generate pdf files on Webpage html. I hope this method will be helpful to you.

Finally, I found an open-source program developed based on the FPDF and HTML2FPDF source code. It basically solves the problem of garbled characters in Chinese (as well as Japanese, Korean, and Southeast Asia and global languages). It is available in Windows/Linux development environment and does not need to be installed with other components, it is a good news for website developers without VPS and independent servers.

Not much said, the source code name is MPDF, the official address is: http://www.mpdf1.com/has been updated to version 5.6.

Download it from the official website, decompress it to the website directory, and use it.

The Code is as follows: Copy code

<? Php
Include ('mpdf. php ');
$ Mpdf = new mPDF ('utf-8', 'a4 );
$ Mpdf-> useAdobeCJK = true;
$ Mpdf-> SetAutoFont (AUTOFONT_ALL );
$ Mpdf-> SetDisplayMode ('fullpage ');
// $ Mpdf-> watermark_font = 'gb ';
// $ Mpdf-> SetWatermarkText ('Chinese watermark', 0.1 );
$ Url = 'HTTP: // www. Your Domain Name. com /';
$ StrContent = file_get_contents ($ url );
// Print_r ($ strContent); die;
$ Mpdf-> showWatermarkText = true;
$ Mpdf-> SetAutoFont ();
// $ Mpdf-> SetHTMLHeader ('head ');
// $ Mpdf-> SetHTMLFooter ('bottom ');
$ Mpdf-> WriteHTML ($ strContent );
$ Mpdf-> output('ss ');
// $ Mpdf-> output('tmpupload', true );
// $ Mpdf-> output('tmpupload', 'D ');
// $ Mpdf-> Output ();
Exit;
?>

PASS: It should be noted that the PHP file is a UTF-8. You don't have to worry about the code posted by the sky. When you write a box with Garbled text, you can go to config. php $ this-> useAdobeCJK = false; changed to true or must be noted: $ mpdf-> useAdobeCJK = true; official documentation, you can find it on your own.

This is not a perfect method. MPDF can only parse relatively simple css (it cannot parse ul li and other labels in js and css ). Now that the wkhtmltoimage extension is used, you do not care about the use of wkhtmltopdf.

Similarly, wkhtmltoimage 0.11 may cause an error. You need to download version 0.10.0 _ rc2.

32-bit
Wget http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.10.0_rc2-static-i386.tar.bz2
Tar jxf wkhtmltopdf-0.10.0_rc2-static-i386.tar.bz2
Cp wkhtmltoimage-i386/usr/local/bin/wkhtmltopdf
 
64-bit
Wget http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.10.0_rc2-static-amd64.tar.bz2
Mv wkhtmltoimage-0.10.0_rc2-static-amd64.tar.bz2 wkhtmltoimage-0.10.0_rc2-static-amd64.tar
Tar-xvf wkhtmltopdf-0.10.0_rc2-static-amd64.tar
Music wkhtmltoimage-amd64/usr/bin/wkhtmltopdf test wkhtmltopdf http: // www. your domain name. com/your domain name php shell_exec () execute shell_exec ('/usr/local/bin/wkhtmltopdf http: // www. your domain name. com // usr/local/wwwroot/your domain name. com/your domain name '); do you want to save your favorite articles? Associate now or create an account without searching?
No longer prompt!

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.