本文主要需求是将html页面转换为pdf文档

1、安装mpdf工具类 (composer方式)

composer require mpdf/mpdf:8.0.3

 

2、控制器里调用

<?php

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文件到指定目录  
} 

?>

 

3、效果如下图

【PHP】使用mpdf生成pdf文件

 

 

 

  

 

  

相关文章:

  • 2022-01-27
  • 2021-12-23
  • 2021-11-30
  • 2021-12-23
  • 2021-12-19
猜你喜欢
  • 2021-12-03
  • 2022-12-23
  • 2021-10-08
  • 2022-12-23
  • 2021-11-25
  • 2021-04-12
  • 2021-12-28
相关资源
相似解决方案