PHP implementation of HTML-generated PDF file method, _php tutorial

Source: Internet
Author: User
Tags wkhtmltopdf

PHP implementation of HTML to generate PDF file method,


The example of this paper describes the use of Html2fpdf and Wkhtmltoimage in Linux to generate HTML directly in PDF format file method, share to everyone for your reference. The implementation method is as follows:

Find a fpdf and Html2fpdf source code based on the development of a set of open-source programs, the author is very powerful. Basically solve the problem of Chinese (and Japanese, Korean and Southeast Asian and global languages) garbled, testing in the Windows/linux development environment is available, do not need to install other components support, is not a VPS and independent server Web site developers of the Gospel.

Not much to say, the source name is Mpdf, the official address is: http://www.mpdf1.com/has been updated to version 5.6.
To the official website to download, unzip to the site directory, use.

The

copy Code code is as follows: <?php
include (' mpdf.php ');
$mpdf =new mpdf (' UTF-8 ', ' A4 ', ' ', ', ' 15,15,44,15 ');
$mpdf->USEADOBECJK = true;
$mpdf->setautofont (Autofont_all);
$mpdf->setdisplaymode (' fullpage ');
//$mpdf->watermark_font = ' GB ';
//$mpdf->setwatermarktext (' China Watermark ', 0.1);
$url = ' http://www. your domain name. com/';
$strContent = file_get_contents ($url);
//print_r ($strContent);d ie;
$mpdf->showwatermarktext = true;
$mpdf->setautofont ();
//$mpdf->sethtmlheader (' head ');
//$mpdf->sethtmlfooter (' bottom ');
$mpdf->writehtml ($strContent);
$mpdf->output (' ss.pdf ');
//$mpdf->output (' tmp.pdf ', true);
//$mpdf->output (' tmp.pdf ', ' d ');
//$mpdf->output ();
Exit;
?
PASS: It is important to note that PHP files are UTF-8. Do not feel the sky posted code, their own writing when the box garbled, can be in the config.php file $THIS->USEADOBECJK = False, modified to TRUE or must be labeled: $mpdf->USEADOBECJK = true; Official documents are available to explore on their own.

This imperfect method, Mpdf can only parse the relatively simple CSS (cannot parse JS and CSS in the UL Li and other tags). Now that you have used the wkhtmltoimage extension, you don't care about the use of wkhtmltopdf.
Similarly, Wkhtmltoimage 0.11 will have an error and need to download version 0.10.0_rc2.

32-bit:
Copy the Code code as follows: 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 guests
Copy the Code code as follows: 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
MV Wkhtmltoimage-amd64/usr/bin/wkhtmltopdf Test wkhtmltopdf http://www. Your domain name. com/your domain name. pdfphp 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. pdf ');

I hope this article is helpful to everyone's PHP programming.




http://www.bkjia.com/PHPjc/907840.html www.bkjia.com true http://www.bkjia.com/PHPjc/907840.html techarticle PHP Implementation of HTML-generated PDF file method, this article describes the use of Html2fpdf and Wkhtmltoimage in Linux, the HTML directly generated in PDF format file method, share to everyone for everyone to participate ...

  • Related Article

    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.