PHP implements the html pdf file generation program

Source: Internet
Author: User
Tags bz2 wkhtmltopdf

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: 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 ();

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.

Tar jxf wkhtmltopdf-0.10.0_rc2-static-i386.tar.bz2
Cp wkhtmltoimage-i386/usr/local/bin/wkhtmltopdf
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!

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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: and provide relevant evidence. A staff member will contact you within 5 working days.