使用php实现导出pdf(mpdf扩展)

安装扩展

composer require mpdf/mpdf

使用

'/vendor/autoload.php'; // 如果使用Composer
 
// 或者如果手动下载,使用下面的路径
// require_once __DIR__ . '/path/to/mpdf/src/Mpdf.php';
 // 'autoScriptToLang' => true,'autoLangToFont'   => true,解决中文乱码问题
$mpdf = new \Mpdf\Mpdf([
    'mode' => 'utf-8', // 使用UTF-8编码
    'format' => 'A4-L', // 设置纸张格式为A4横向
    'margin_left' => 15, // 设置左边距为15mm
    'margin_right' => 15, // 设置右边距为15mm
    'autoScriptToLang' => true, // 自动识别语言脚本
    'autoLangToFont'   => true, // 自动匹配语言对应字体
    'useSubstitutions' => true    // 启用字符替换(解决符号乱码)
]);
 // 不支持css:display:flex;display:grid;(可用float代替)...
$html = '

Hello, World!

This is a simple example of using MPDF to generate a PDF file.

"box">
'; $mpdf->WriteHTML($html); $mpdf->Output(); // 输出PDF到浏览器,也可以保存到文件:$mpdf->Output('filename.pdf', \Mpdf\Output\Destination::FILE);

你可能感兴趣的:(php,php,pdf)