京东6.18大促主会场领京享红包更优惠

 找回密码
 立即注册

QQ登录

只需一步,快速开始

PHP利用mpdf实现导出pdf文件功能

2024-11-4 10:52| 发布者: 284cc| 查看: 114| 评论: 0

摘要: mpdf的开发文档地址: Supported CSS – CSS & Stylesheets – mPDF Manual 1.加载依赖库 [code]composer require mpdf/mpdf [/code] 2.页面 [code]$html = <<<EOD <body style="background:url($img1

mpdf的开发文档地址:

Supported CSS – CSS & Stylesheets – mPDF Manual

1.加载依赖库

[code]composer require mpdf/mpdf [/code]

2.页面

[code]$html = <<<EOD <body style="background:url($img1);" lang="zh-CN"> <div style="background:rgba(255,255,255,0.3);"> <div style="width: 12rem;height: 15rem;float: right;"> $avatar </div> <div style="padding-top: 5rem;padding-left: 2rem;"> <span style="font-size: 20pt;font-weight: bold;">$strTitle</span> <table style="color: #666666;padding-top: 1rem;font-size: 14pt;line-height: 16pt;" > <tr> <td style=""> 姓名:$studentName </td> <td style="padding-left: 2rem;"> 性别:$sex </td> <td style=""> 出生年代:$birthday </td> </tr> <tr> <td> 民族:$nationality </td> <td style=""> 政治面貌:$political </td> <td style="padding-left: 2rem;"> 电话:$phone </td> </tr> </table> </div> </div> <div style="background-color: white;padding-bottom: initial;"> <table style="text-align:center;font-size:20pt;" > </table> <h2></h2><h2></h2> <h2 style="padding-left: 2rem">技能特长</h2> <table style="text-align:left;line-height:200%;font-size:14pt;color: #666666;" > $strSkills </table> <h2></h2> <h2 style="padding-left: 2rem">成绩单</h2> <table style="text-align:left;line-height:200%;font-size:12pt;border-collapse: collapse;margin-left: 2rem;width: 95%;" > <tr > <th style="border: 1px solid black;border-right: 0px;">总分:$scoreTotal</th> <th style="border: 1px solid black;border-right: 0px;border-left: 0px;"></th> <th style="border: 1px solid black;border-right: 0px;border-left: 0px;"></th> <th style="border: 1px solid black;border-right: 0px;border-left: 0px;"></th> <th style="border: 1px solid black;border-left: 0px;"></th> </tr> $strActivity </table> <h2></h2> <h2 style="padding-left: 2rem;">获奖证书</h2> <table style="text-align:left;line-height:200%;font-size:12pt;border-collapse: collapse;margin-left: 2rem;width: 95%;" > <tr> <th style="border: 1px solid black;color: #333333;">项目名称</th> <th style="border: 1px solid black;color: #333333;">等级</th> <th style="border: 1px solid black;color: #333333;">获得时间</th> <th style="border: 1px solid black;color: #333333;">履历形貌</th> </tr> $strCertificate </table> <h2></h2> <h2 style="padding-left: 2rem;">实践履历</h2> $strTraining <h2></h2> <h2 style="padding-left: 2rem;">个人风采</h2> $strPersona </div> </body> EOD;[/code]

3.导出

[code]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, 'margin_bottom' => 10, 'margin_header' => 9, 'margin_footer' => 9, 'orientation' => 'P', ]); $mpdf->useAdobeCJK = true; $mpdf->autoScriptToLang = true;//支持中文设置 $mpdf->autoLangToFont = true;//支持中文设置 $mpdf->setAutoTopMargin = 'stretch';//设置自动顶部边距 $mpdf->setAutoBottomMargin = 'stretch';//设置自动低部边距 $mpdf->AddPage(); //获取配置文字大概logo $conf=M("confScoreList")->find(); //设置页眉 $SetHeader = '<table class="header" style="text-align: right;width: 100%;"> <tr> <td width="33%" style="text-align: left;font-size: 10pt;color: #999999;"> <img src="'.K_PATH_IMAGES.$conf['logo'].'" alt=""> </td> <td width="33%" style="text-align: right;color: #999999;">'.$conf['headerRight'].'</td> </tr> </table>'; $mpdf->SetHeader($SetHeader); //这是一个页脚的范例{PAGENO}是当前的页数,{nb}是总共的页数 //<td width="33%" style="text-align: center;font-size: 10pt;">第 {PAGENO} 页&nbsp;&nbsp;&nbsp;&nbsp;共 {nb} 页</td> $setFooter = '<table class="footer" style="text-align: right;width: 100%;"> <tr> <td width="33%" style="text-align: left;font-size: 10pt;color: #999999;">'.$conf['footerLeft'].'</td> <td width="33%" style="text-align: right;color: #999999;">'.$conf['footerRight'].'</td> </tr> </table>'; $mpdf->setFooter($setFooter); //设置中文编码 $mpdf->WriteHTML($html); //导出pdf文件重命名 // $mpdf->Output($dataResume['resumeName'] . '.pdf', true); $mpdf->Output(); exit;[/code]

到此这篇关于PHP利用mpdf实现导出pdf文件功能的文章就介绍到这了,更多相关PHP mpdf导出pdf内容请搜刮脚本之家从前的文章或继承欣赏下面的相关文章希望大家以后多多支持脚本之家!


来源:https://www.jb51.net/program/320203oh0.htm
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
关闭

站长推荐上一条 /6 下一条

QQ|手机版|小黑屋|梦想之都-俊月星空 ( 粤ICP备18056059号 )|网站地图

GMT+8, 2025-7-1 21:15 , Processed in 0.029639 second(s), 18 queries .

Powered by Mxzdjyxk! X3.5

© 2001-2025 Discuz! Team.

返回顶部