mpdf导出pdf文件实例

代码:

<?php
require 'mpdf/mpdf.php';
$str = '
    <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="2">
                <img src="images/order_logo.png">
            </td>-->
            <td style="font-weight: bold;font-size:40px;text-align:center" colspan="8">
                《出库单》
            </td>
            <!--<td style="font-weight: bold;font-size:40px;text-align:right" colspan="2">
                <img src="条形码.jpg" width="300px" height="54px">
            </td>-->
        </tr>
        <tr>
            <td style="border-bottom: 1px solid #ccc;font-size:28px;text-align:right" colspan="8">
                合同号XXXXXX
            </td>
        </tr>
        <tr style="height:75px;"><td colspan="8">&nbsp;</td></tr>
        <tr style="height:40px;text-align:left;">
            <td style="font-weight: normal;font-size:12px;" colspan="4">
                【打印时间】2019/07/09 03:44:35
            </td>
            <td style="font-weight: normal;font-size:12px;text-align:right">
                【客户国家】
            </td>
            <td style="font-weight: normal;font-size:12px;" colspan="3">
                XXXXX
            </td>
        </tr>
        <tr style="height:75px;"><td colspan="8">&nbsp;</td></tr>
        <tr style="height:40px;text-align:left">
            <td style="font-weight: normal;font-size:12px;" colspan="4">
                【录入时间 】2019-07-09 12:29:05 
            </td>
            <td style="font-weight: normal;font-size:12px;text-align:right">
                【运输方式】
            </td>
            <td style="font-weight: normal;font-size:12px;" colspan="3">
                XXXXXXXXXXXXXX
            </td>
        </tr>
        <tr style="height:75px;"><td colspan="8">&nbsp;</td></tr>
        <tr style="height:40px;text-align:left">
            <td style="font-weight: normal;font-size:12px;" colspan="1">
                【付款方式】
            </td>
            <td style="font-weight: normal;font-size:12px;" colspan="3">
                XXXXXXXXXXXX
            </td>
            <td style="font-weight: normal;font-size:12px;text-align:right">
                【客户备注】
            </td>
            <td style="font-weight: normal;font-size:12px;" colspan="3">
                XXXXXXXXXX
            </td>
        </tr>
        <tr style="height:75px;"><td colspan="8">&nbsp;</td></tr>
        <tr style="height:40px;text-align:left">
            <td style="font-weight: normal;font-size:12px;" colspan="2">
                【业务助理/业务员/填单助理】:
            </td>
            <td style="font-weight: normal;font-size:12px;" colspan="6">
                XXXXXXXXXXXXX
            </td>
        </tr>
        <tr style="height:75px;"><td colspan="8" style="border-bottom: 1px solid #ccc;">&nbsp;</td></tr>
        
        <tr style="height:75px;"><td colspan="8">&nbsp;</td></tr>
        <tr style="height:32px;text-align:center;font-size:14px">
            <td style="border: 1px solid #ccc;font-weight: normal; width: 8%;text-align:center;font-size:14px;">
                ID
            </td>
            <td style="border: 1px solid #ccc;font-weight: normal; width: 19%;text-align:center;font-size:14px;">
                产品名称
            </td>
            <td style="border: 1px solid #ccc;font-weight: normal; width: 8%;text-align:center;font-size:14px;">
                主产品ID
            </td>
            <td style="border: 1px solid #ccc;font-weight: normal; width: 5%;text-align:center;font-size:14px;">
                数量
            </td>
            <td style="border: 1px solid #ccc;font-weight: normal;width: 17%;text-align:center;font-size:14px;">
                特性备注
            </td>
            <td style="border: 1px solid #ccc;font-weight: normal;width: 16%;text-align:center;font-size:14px;">
                装箱单标签
            </td>
            <td style="border: 1px solid #ccc;font-weight: normal;width: 10%;text-align:center;font-size:14px;">
                发货区
            </td>
            <td style="border: 1px solid #ccc;font-weight: normal;width: 17%;text-align:center;font-size:14px;">
                采购人及备注
            </td>
        </tr>
        <tr style="height:32px;text-align:center;font-size:14px;text-align:center">
            <td style="border: 1px solid #ccc;font-weight: normal;text-align:center;font-size:14px;">
                <img src="产品.jpg" width="50px" height="50px"><br>
                #42465
            </td>
            <td style="border: 1px solid #ccc;font-weight: normal;text-align:center;font-size:14px;">
                XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
            </td>
            <td style="border: 1px solid #ccc;font-weight: normal;text-align:center;font-size:14px;">
                XXXXXXXXXXXX
            </td>
            <td style="border: 1px solid #ccc;font-weight: normal;text-align:center;font-size:14px;">
                5
            </td>
            <td style="border: 1px solid #ccc;font-weight: normal;text-align:center;font-size:14px;">
                标签描述: XXXXXXXXX
            </td>
            <td style="border: 1px solid #ccc;font-weight: normal;text-align:center;font-size:14px;">
                XXXXXXXXXXXXX
            </td>
            <td style="border: 1px solid #ccc;font-weight: normal;text-align:center;font-size:14px;">
                XXXXXXXXXXX
            </td>
            <td style="border: 1px solid #ccc;font-weight: normal;text-align:center;font-size:14px;">
                XXXXXXXXXXXXX
            </td>
        </tr>
    </tbody>
</table>
';
$mpdf = new mPDF('utf-8', 'A4', 16, '', 10, 10, 15, 1);
$mpdf->SetDisplayMode('fullpage');
$mpdf->autoScriptToLang = true;
$mpdf->autoLangToFont = true;
$mpdf->WriteHTML($str, 2);
$mpdf->Output('mpdf.pdf', 'I'); //D是下载
?>

效果图:

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以使用第三方库如TCPDFmPDF来实现在PHP中将网页导出PDF文件。 以下是使用TCPDF实现的示例代码: ```php <?php require_once('tcpdf/tcpdf.php'); // 创建PDF对象 $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); // 设置文档信息 $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor('作者'); $pdf->SetTitle('标题'); $pdf->SetSubject('主题'); $pdf->SetKeywords('关键词'); // 设置页眉和页脚信息 $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING); $pdf->setFooterData(array(0,64,0), array(0,64,128)); // 设置页眉和页脚字体 $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); // 设置默认字体 $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); // 设置间距 $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); $pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); // 设置自动分页 $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); // 设置图像比例因子 $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); // 设置字体 $pdf->SetFont('stsongstdlight', '', 14); // 将HTML转换为PDF $pdf->AddPage(); $html = '<h1>Hello, world!</h1><p>This is a sample PDF document created with TCPDF.</p>'; $pdf->writeHTML($html, true, false, true, false, ''); // 输出PDF文件 $pdf->Output('example.pdf', 'D'); ``` 以上代码将在当前目录中生成名为"example.pdf"的PDF文件,可以在浏览器中下载。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值