PHP uses Mpdf class to generate PDF _php Instance

Source: Internet
Author: User

Due to the business needs of the company, recently, the need to create a PDF of HTML static files, found on the internet a lot of class files to achieve, the effect is not very good. The first use is tcpdf this class is particularly slow, and the current version has a very annoying problem-css background images are not available, Found a lot of information can not be solved. Finally discovered that mpdf may realize this function, overjoyed, and efficiency also faster than tcpdf.

Mpdf's official download address: Http://www.mpdf1.com/mpdf/download

After downloading an example, you can make a reference to do a know. Of course, the official website also has the example, the website: http://mpdf1.com/common/mpdf/examples/

Documents provided by the Government: http://mpdf1.com/manual/

<?php * * Function: Generate user Diagnostic report PDF file * Create time:--* *//phpinfo (); exit;
Introduction of Mpdf class file Set_time_limit ();
Include '/include/mpdf/mpdf.php ';
Instantiate mpdf $mpdf =new mpdf (' utf-', ' A ', ', ', ' Arial ',,,,);
Set the font to solve the Chinese garbled $mpdf-&GT;USEADOBECJK = true;
$mpdf->setautofont (Autofont_all);
Gets the static file to be generated $html =file_get_contents (' template.html ');
Echo $html, exit; Set the PDF header content $header = ' <table width= '% ' style= ' margin:auto;border-bottom:px solid #FBD; Vertical-align:middle; Font-family:serif; font-size:pt; Color: #; ><tr> <td width= "%" ></td> <td width= "%" align= "center" style= "Font-size:px;color: #AAA" > Header </td> <td width= "%" style= "text-align:right;"
></td> </tr></table> '; Set the PDF footer Content $footer = ' <table width= '% ' style= ' vertical-align:bottom; Font-family:serif; font-size:pt; Color: #; ><tr style= "height:px" ></tr><tr> <td width= "%" ></td> <td width= "%" align= "center "Style=" Font-size:px;color: #AAA "> Footer </td> <td width= "%" style= "text-align:left;"
> page:{pageno}/{nb}</td> </tr></table> ';
Add headers and footers to the PDF $mpdf->sethtmlheader ($header);
$mpdf->sethtmlfooter ($footer);
Set the PDF display mode $mpdf->setdisplaymode (' fullpage ');
Set the size of the PDF to mm*mm//$mpdf->writehtml (' <pagebreak sheet-size= mm '/> ');
Create PDF file $mpdf->writehtml ($html);
Delete the first page of the PDF (due to the size of the PDF resulting in one more page)//$mpdf->deletepages (,);
Output PDF $mpdf->output ();  Exit;?>

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.