安装mpdf包,然后调用即可~
1、使用composer安装mpdf
composer require mpdf/mpdf
public function test_pdf(){ //$mpdf = new \Mpdf\Mpdf(); $mpdf = new \Mpdf\Mpdf([ 'mode' => 'UTF-8', 'format' => 'A4', 'default_font_size' => 40, 'default_font' => '', 'margin_left' => 20, 'margin_right' => 20 ]); $mpdf->autoScriptToLang = true;//支持中文设置 $mpdf->autoLangToFont = true;//支持中文设置 $mpdf->WriteHTML('<h1>你好啊,世界!hello word</h1><p style="color: blue;fontsize:14px;">http://www.baidu.com</p>'); $path = FILE_UPLOAD.date('YmdHis').'_'.mt_rand(1,5).'.pdf'; $mpdf->Output();//直接在页面显示pdf页面内容 //$mpdf->Output($path,'f');//保存pdf文件到指定目录 } ?>