php使用mpdf扩展将html转换成pdf

require_once APP_PATH . '/vendor/autoload.php';

$mpdf = new \Mpdf\Mpdf([
    'mode' => 'UTF-8', 'format' => 'A4', 'default_font_size' => 40, 'default_font' => '', 'margin_left' => 20, 'margin_right' => 20]);

$path = BASE_PATH. '/resource/' .date('YmdHis').'_'.mt_rand(1,5).'.pdf';
$mpdf->autoScriptToLang = true;//支持中文设置
$mpdf->autoLangToFont = true;//支持中文设置
$url = 'http://baidu.com’;
$strContent = file_get_contents($url);
$mpdf->WriteHTML($strContent);

$mpdf->Output($path,'f');
exit;

你可能感兴趣的:(php使用mpdf扩展将html转换成pdf)