类库下载
composer require mpdf/mpdf
3、控制器代码
use Mpdf\Mpdf;
public function createPdf()
{
//为了防止文件下载的时候出现跨域问题
header("Content-type: text/html; charset=utf-8");
$mpdf = new Mpdf();
//自动识别文字字符
$mpdf->autoScriptToLang = true;
$mpdf->autoLangToFont = true;
//要生成的html文件
$html = '<table style="border-collapse: collapse; width: 900px; height: 56px; font-family: 宋体; font-size: 18px; position: relative;">
<tbody>
<tr style="height:75px;text-align:center" class="firstRow">
<td style="font-weight: bold;font-size:40px;text-align:center" colspan="8">
购 销 合 同
</td>
</tr>
<tr style="height:75px;">
<td colspan="8">
</td>
</tr>
<tr style="height:32px;text-align:left">
<td style="font-weight: normal;" colspan="4">
买方:{buyer_company_name}
</td>
<td style="font-weight: normal;"></td>
<td style="font-weight: normal; text-align: right; word-break: break-all;">
合同编号:
</td>
<td style="font-weight: normal;" colspan="2">
{order_key}
</td>
</tr>
<tr style="height:32px">
<td style="font-weight: normal;"></td>
<td style="font-weight: normal;"></td>
<td style="font-weight: normal;"></td>
<td style="font-weight: normal;"></td>
<td style="font-weight: normal;"></td>
<td style="font-weight: normal;text-align:right">
签订地点:
</td>
<td style="font-weight: normal;"></td>
<td style="font-weight: normal;"></td>
</tr>
<tr style="height:32px">
<td style="font-weight: normal;" colspan="4">
卖方:{supply_company_name}
</td>
<td style="font-weight: normal;"></td>
<td style="font-weight: normal; text-align: right; word-break: break-all;">
签订时间:
</td>
<td style="font-weight: normal; word-break: break-all;" colspan="2">
{current_time}
</td>
</tr>
<tr style="height:32px">
<td style="font-weight: normal;"></td>
<td style="font-weight: normal;"></td>
<td style="font-weight: normal;"></td>
<td style="font-weight: normal;"></td>
<td style="font-weight: normal;"></td>
<td style="font-weight: normal;"></td>
<td style="font-weight: normal;"></td>
<td style="font-weight: normal;"></td>
</tr>
<tr style="height:75px;">
<td colspan="8">

本文介绍了一种使用PHP和MPDF库自动生成购销合同PDF的方法。通过编写控制器代码,可以将HTML模板转换为PDF文件,便于下载和打印。
最低0.47元/天 解锁文章
1837

被折叠的 条评论
为什么被折叠?



