Home > Article > Backend Development > The best class MPDF for generating PDF in php
The official download address of mpdf: http://www.mpdf1.com/mpdf/download
There are examples after downloading, you can refer to it and make one. Of course, the official website also has examples, URL: http://mpdf1 .com/common/mpdf/examples/
Officially provided documents: http://mpdf1.com/manual/
<?php /* *功能:生成用户诊断报告PDF文件 *创建时间:2013-09-12 */ //phpinfo();exit; //引入MPDF类文件 set_time_limit(0); include '/include/MPDF57/mpdf.php'; //实例化mpdf $mpdf=new mPDF('utf-8','A4','','宋体',0,0,20,10); //设置字体,解决中文乱码 $mpdf->useAdobeCJK = true; $mpdf->SetAutoFont(AUTOFONT_ALL); //获取要生成的静态文件 $html=file_get_contents('template.html'); echo $html;exit; //设置PDF页眉内容 $header='<table width="95%"><tr> <td width="10%"></td> <td width="80%" align="center">页眉</td> <td width="10%"></td> </tr></table>'; //设置PDF页脚内容 $footer='<table width="100%"><tr></tr><tr> <td width="10%"></td> <td width="80%" align="center">页脚</td> <td width="10%">页码:{PAGENO}/{nb}</td> </tr></table>'; //添加页眉和页脚到pdf中 $mpdf->SetHTMLHeader($header); $mpdf->SetHTMLFooter($footer); //设置pdf显示方式 $mpdf->SetDisplayMode('fullpage'); //设置pdf的尺寸为270mm*397mm //$mpdf->WriteHTML('<pagebreak sheet-size="270mm 397mm" />'); //创建pdf文件 $mpdf->WriteHTML($html); //删除pdf第一页(由于设置pdf尺寸导致多出了一页) //$mpdf->DeletePages(1,1); //输出pdf $mpdf->Output(); exit; ?>
The above introduces the best MPDF class for generating PDF in PHP, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.