PHP使用mpdf實(shí)現(xiàn)導(dǎo)出pdf文件功能
mpdf的開發(fā)文檔地址:
Supported CSS – CSS & Stylesheets – mPDF Manual
1.加載依賴庫
composer require mpdf/mpdf
2.頁面
$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;">項(xiàng)目名稱</th>
<th style="border: 1px solid black;color: #333333;">等級</th>
<th style="border: 1px solid black;color: #333333;">獲得時(shí)間</th>
<th style="border: 1px solid black;color: #333333;">經(jīng)歷描述</th>
</tr>
$strCertificate
</table>
<h2></h2>
<h2 style="padding-left: 2rem;">實(shí)踐經(jīng)歷</h2>
$strTraining
<h2></h2>
<h2 style="padding-left: 2rem;">個(gè)人風(fēng)采</h2>
$strPersona
</div>
</body>
EOD;3.導(dǎo)出
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;//支持中文設(shè)置
$mpdf->autoLangToFont = true;//支持中文設(shè)置
$mpdf->setAutoTopMargin = 'stretch';//設(shè)置自動頂部邊距
$mpdf->setAutoBottomMargin = 'stretch';//設(shè)置自動低部邊距
$mpdf->AddPage();
//獲取配置文字或者logo
$conf=M("confScoreList")->find();
//設(shè)置頁眉
$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);
//這是一個(gè)頁腳的范例{PAGENO}是當(dāng)前的頁數(shù),{nb}是總共的頁數(shù)
//<td width="33%" style="text-align: center;font-size: 10pt;">第 {PAGENO} 頁 共 {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);
//設(shè)置中文編碼
$mpdf->WriteHTML($html);
//導(dǎo)出pdf文件重命名
// $mpdf->Output($dataResume['resumeName'] . '.pdf', true);
$mpdf->Output();
exit;到此這篇關(guān)于PHP使用mpdf實(shí)現(xiàn)導(dǎo)出pdf文件功能的文章就介紹到這了,更多相關(guān)PHP mpdf導(dǎo)出pdf內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
PHP實(shí)現(xiàn)通過strace定位故障原因的方法
這篇文章主要介紹了PHP實(shí)現(xiàn)通過strace定位故障原因的方法,結(jié)合實(shí)例形式分析了出現(xiàn)高負(fù)載情況下使用strace定位故障原因的相關(guān)命令與操作技巧,需要的朋友可以參考下2018-04-04
PHP學(xué)習(xí)之?dāng)?shù)組值的操作
PHP中,用list來析取數(shù)組中的值,如list($a, $b) = $array。2011-04-04
PHP/ThinkPHP實(shí)現(xiàn)批量打包下載文件的方法示例
最近因?yàn)楣ぷ鞯男枰?,要根?jù)條件自動打包供下載的功能,查找相關(guān)資料終于解決了,所以下面這篇文章主要給大家介紹了利用PHP或者ThinkPHP如何實(shí)現(xiàn)批量打包下載文件的方法示例,需要的朋友可以參考借鑒,下面來一起看看吧。2017-07-07
基于PHP實(shí)現(xiàn)堆排序原理及實(shí)例詳解
這篇文章主要介紹了基于PHP實(shí)現(xiàn)堆排序原理及實(shí)例詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-06-06
PHP 數(shù)據(jù)結(jié)構(gòu) 算法 三元組 Triplet
PHP 數(shù)據(jù)結(jié)構(gòu) 算法 三元組 Triplet,學(xué)習(xí)php的朋友可以參考下。2011-07-07

