php html mpdf自动转换并生成pdf文件

    科技2022-07-16  98

    <?php require '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"> </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"> </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"> </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"> </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;"> </td></tr> <tr style="height:75px;"><td colspan="8"> </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是下载 //$mpdf->Output('mpdf.pdf', 'D'); //D是下载 $mpdf->Output(iconv("utf-8","GB2312","D:/MYOA/pdf/生成PDF.pdf"));//将生成的pdf文件存在指定的路径里 ?>

     

    Processed: 0.008, SQL: 8