$mpdf = new Mpdf();
$mpdf->AddPage();
$mpdf->SetDisplayMode('fullpage');
$mpdf->showImageErrors = true;//开启图片地址报错信息
$mpdf->autoScriptToLang = true;
$mpdf->autoLangToFont = true;
//图片渲染
//这里假如是远程图片地址,直接放到src导出pdf不渲染(本地图片自己测试)
//需要base64转码
$img = “https://www.baidu.com”;
$baseImg = base64_encode(file_get_contents($img));
$img = 'data:image/png;base64,'.$baseImg ;//这里image/png根据图片类型自己调整
$html = '<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.title {
text-align: center;
font-weight: 500;
font-size: 36px;
margin-bottom: 20px;
}
</style>
</head>
<body>
<div class="title">Hello world</div>
<img src="'.$img.'"></img>
</body>
</html>';
$mpdf->WriteHTML($html);
$mpdf->Output(public_path("out.pdf"), 'F');//F保存文件,D下载,S打印字符串,I网页预览
网友评论