Due to the company's business needs, the recent 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 of tcpdf this class is particularly slow, and the current version has a very annoying problem-css background image can not be obtained, Find a lot of information can not be solved. Finally found that mpdf may achieve this function, overjoyed, and efficiency is faster than tcpdf.
Mpdf's official download address: Http://www.mpdf1.com/mpdf/download
After the download there are instances, you can refer to do one to know. Of course, the official website also has examples, website: http://mpdf1.com/common/mpdf/examples/
Documents provided by the Government: http://mpdf1.com/manual/
<?php/** function: Generate user Diagnostic report PDF file * Creation time:--*///phpinfo (); exit;//introduces MPDF class file Set_time_limit (); include '/include/mpdf/ Mpdf.php ';//Instantiate Mpdf$mpdf=new mpdf (' utf-', ' A ', ' ', ' Arial ',,,,);//Set font, solve Chinese garbled $mpdf->useadobecjk = true; $mpdf Setautofont (Autofont_all);//Gets the static file to generate $html=file_get_contents (' template.html '); echo $html; exit;//Set PDF header contents $ Header= '
';//Set PDF footer Content $footer= '
|
Footer |
Page number: {PAGENO}/{NB} |
///Add headers and footers to PDF $mpdf->sethtmlheader ($header), $mpdf->sethtmlfooter ($footer),//Set PDF display $mpdf-> Setdisplaymode (' fullpage ');//Set the PDF size to mm*mm//$mpdf->writehtml ('
')///Create PDF file $mpdf->writehtml ($html);//delete the first page of PDF (due to the size of the PDF)//$mpdf->deletepages (,);//Output pdf$mpdf- >output (); exit; >