mpdf的官方下載地址:http://www.mpdf1.com/mpdf/download
下載後裡面有實例,可以參照著做一個就知道了.當然官方網站也有實例,網址:http://mpdf1.com/common/mpdf/examples/
官方提供的文檔: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%" style="margin:0 auto;border-bottom: 1px solid #4F81BD; vertical-align: middle; font-family:
serif; font-size: 9pt; color: #000088;"><tr>
<td width="10%"></td>
<td width="80%" align="center" >頁眉</td>
<td width="10%" ></td>
</tr></table>';
//設置PDF頁腳內容
$footer='<table width="100%" style=" vertical-align: bottom; font-family:
serif; font-size: 9pt; color: #000088;"><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;
?>