PHP implements the html pdf file generation program. 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 a method to use HTML2FPDF and wkhtmltoimage in linux to directly generate a file in pdf format for 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: |
|
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!
Bytes. Finally found...