PHP使用mpdf实现导出pdf文件功能
mpdf的开发文档地址:
Supported css – CSS & Stylesheets – mPDF Manual
1.加载依赖库
composer require mpdf/mpdf
2.页面
$html = <<<EOD <body lang="zh-CN"> <div> <div> $avatar </div> <div> <span>$strTitle</span> <table > <tr> <td> 姓名:$studentName </td> <td> 性别:$sex </td> <td> 出生年月:$birthday </td> </tr> <tr> <td> 民族:$nationality </td> <td> 政治面貌:$political </td> <td> 电话:$phone </td> </tr> </table> </div> </div> <javascriptdiv> <table > </table> <h2></h2><h2></h2> <h2>技能特长</h2> <table > $strSkills </table> <h2></h2> <h2>成绩单</h2> <table > <tr > <th>总分:$scoreTotal</th> <th></th> <th></th> <th></th> <th></th> </tr> $strActivity </table> <h2></h2> <h2>获奖证书</h2> <table > <tr> <th>项目名称</th> <th>等级</th> <th>获得时间</th> <th>经历描述</th> </tr> $strCertificate </table> <h2></h2> <h2>实践经历</h2> $strTraining <h2></h2> <h2>个人风采</h2> $strPersona </div> </body> EOD;
3.导出
require_once 'vendor/autoload.php'; $mpdf=new Mpdf([ 'mode' => '', 'format' => 'A4', 'default_font_size' => 0, 'default_font' => 'sans', 'margin_left' => 10, 'margin_right' => 10, 'margin_top' => 10, http://www.devze.com 'margin_bottom' => 10, 'margin_header' => 9, 'margin_footer' => 9, 'orientation' => 'P', ]); $mpdf->useAdobeCJK = true; $mpdf->autoScriptToLang = true;//支持中文设置 $mpdf->autoLangToFont = true;//支持中文设置 $mpdf->setAutoTopMargin = 'stretch';//设置自动顶部边距 $mpdf->setAutoBottomMaphprgin = 'stretch';//设置自动低部边距 $mpdf->AddPage(); //获取配置文字或者logo $conf=M("confScoreList")->find(); //设置页眉 $SetHeader = '<table class="header"> <tr> <td width="33%"> <img src="'.K_PATH_IMAGES.$conf['logo'].http://www.devze.com'" alt="PHP使用mpdf实现导出pdf文件功能"> </td> <td width="33%">'.$conf['headerRight'].'</编程客栈td> </tr> </table>'; $mpdf->SetHeader($SetHeader); //这是一个页脚的范例{PAGENO}是当前的页数,{nb}是总共的页数 //<td width="33%">第 {PAGENO} 页 共 {nb} 页</td> $setFooter = '<table class="footer"> <tr> <td width="33%">'.$conf['footerLeft'].'</td> <td width="33%">'.$conf['footerRight'].'</td> </tr> </table>'; $mpdf->setFooter($setFooter); //设置中文编码 $mpdf->WriteHTML($html); //导出pdf文件重命名 // $mpdf->Output($dataResume['resumeName'] . '.pdf', true); $mpdf->Output(); exit;
到此这篇关于PHP使用mpdf实现导出pdf文件功能的文章就介绍到这了,更多相关PHP mpdf导出pdf内容请搜索编程客栈(www.devze.com)以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程客栈(www.devze.com)!
精彩评论