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->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;?>