大概写法:
public function generate_pdf($order_sn)
{
include('vendor/mpdf/mpdf.php');
$path = SITE_URL.'/index/pdf/heyue?order_sn='.$order_sn;
$mpdf = new \mPDF('zh-CN', 'A4', '', '', 20, 20, 20, 20);
$mpdf->useAdobeCJK = true;
$html = file_get_contents($path);
$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" style="font-size:16px;color:#A0A0A0">页眉</td>
<td width="10%" style="text-align: right;"></td>
</tr></table>';
$footer = '<table width="100%" style=" vertical-align: bottom; font-family:
serif; font-size: 9pt; color: #000088;"><tr style="height:30px"></tr><tr>
<td width="10%"></td>
<td width="80%" align="center" style="font-size:14px;color:#A0A0A0">页脚</td>
<td width="10%" style="text-align: left;">页码:{PAGENO}/{nb}</td>
</tr></table>';
$mpdf->SetHTMLHeader($header);
$mpdf->SetHTMLFooter($footer);
$mpdf->useAdobeCJK = true;
$mpdf->autoScriptToLang = true;
$mpdf->autoLangToFont = true;
$mpdf->SetDisplayMode('fullpage');
$mpdf->WriteHTML($html);
$file_path = APP_PATH.'/public/uploadpdf/'.Date('Ymd');
if(!is_dir($file_path)){
mkdir($file_path,0777,true);
}
$Name = $order_sn.Date('His').'.pdf';
$fileName = $file_path.'/'.$Name;
$mpdf->Output($fileName);
$data_path = '/public/uploadpdf/'.Date('Ymd').'/'.$Name;
return $data_path;
}