php - mpdf 发票未按我想要的方式生成

标签 php javascript jquery pdf mpdf

这是我用来生成 pdf 发票的编码,我使用 jquery 加载 $html 内 php 页面的 div 内容,但它根本没有加载。我尝试使用隐藏字段和 JavaScript,但都不起作用。

<?php

include("mpdf/mpdf.php");



$mpdf=new mPDF('win-1252','A4','','',20,15,48,25,10,10);
$mpdf->useOnlyCoreFonts = true;    // false is default
$mpdf->SetProtection(array('print'));
$mpdf->SetTitle("Acme Trading Co. - Invoice");
$mpdf->SetAuthor("Acme Trading Co.");
$mpdf->SetWatermarkText("Paid");
$mpdf->showWatermarkText = true;
$mpdf->watermark_font = 'DejaVuSansCondensed';
$mpdf->watermarkTextAlpha = 0.1;
$mpdf->SetDisplayMode('fullpage');

$html = '
<html>
<head>
<style>
body {font-family: sans-serif;
   font-size: 10pt;
 }
p {    margin: 0pt;
}
td { vertical-align: top; }
.items td {
 border-left: 0.1mm solid #000000;
border-right: 0.1mm solid #000000;
}
table thead td { background-color: #EEEEEE;
text-align: center;
border: 0.1mm solid #000000;
}
.items td.blanktotal {
background-color: #FFFFFF;
border: 0mm none #000000;
border-top: 0.1mm solid #000000;
border-right: 0.1mm solid #000000;
}
.items td.totals {
text-align: right;
border: 0.1mm solid #000000;
}
</style>

</head>
<body>

<!--mpdf
<htmlpageheader name="myheader">
 <table width="100%"><tr>
 <td width="50%" style="color:#0000BB;"><span style="font-weight: bold; font-size:     14pt;">Acme Trading Co.</span><br />123 Anystreet<br />Your City<br />GD12 4LP<br /><span style="font-size: 15pt;">&#9742;</span> 01777 123 567</td>
 <td width="50%" style="text-align: right;">Invoice No.<br /><span style="font-weight: bold; font-size: 12pt;">0012345</span></td>
 </tr></table>
 </htmlpageheader>

<htmlpagefooter name="myfooter">
<div style="border-top: 1px solid #000000; font-size: 9pt; text-align: center;   padding-top: 3mm; ">
Page {PAGENO} of {nb}
</div>
</htmlpagefooter>

<sethtmlpageheader name="myheader" value="on" show-this-page="1" />
<sethtmlpagefooter name="myfooter" value="on" />
mpdf-->

<div style="text-align: right">Date: '.date('jS F Y').'</div>

<table width="100%" style="font-family: serif;" cellpadding="10">
<tr>
<td width="45%" style="border: 0.1mm solid #888888;"><span style="font-size: 7pt;   color: #555555; font-family: sans;">SOLD TO:</span><br /><br />345 Anotherstreet<br   />Little Village<br />Their City<br />CB22 6SO</td>
<td width="10%">&nbsp;</td>
<td width="45%" style="border: 0.1mm solid #888888;"><span style="font-size: 7pt; color: #555555; font-family: sans;">SHIP TO:</span><br /><br />345 Anotherstreet<br />Little Village<br />Their City<br />CB22 6SO</td>
</tr>
 </table>

        **<div style="font-size:9px" id="serviced"><b>Service :</b></div>
        <script type="text/javascript">
$(document).ready(function(){
$("#serviced").load("http://website.com/service.php #serviced")
})
</script>**
        <div style="font-size:9px" id="tratyped"><b>Type of Transport :</b></div>
        <div style="font-size:9px" id="custyped"><b>Type of Client</b></div>
        <div style="font-size:9px" id="datepickerd"><b>Date :</b></div>
        <div  style="font-size:9px;display:none" id="timed"><b>Time :</b></div>
        <div  style="font-size:9px" id="departured"><b>Departure Address :</b></div>
        <div style="font-size:9px" id="destinationd"><b>Arrival Address</b></div>

        <div style="font-size:9px" id="passengerd"><b>No. of Passengers :</b></div>
        <div style="font-size:9px" id="shairwelld"><b>No. of Chariwells :</b></div>
        <div style="font-size:9px" id="babycd"><b>No. of Baby Chairs :</b></div>
        <div style="font-size:9px" id="companiond"><b>No. of Companions :</b></div>
        <div style="font-size:9px" id="luggaged"><b>No. of Luggages :</b></div>
        <div style="font-size:9px" id="petd"><b>No. of Pets :</b></div>
        <div style="font-size:9px" id="waitingd"><b>Waiting Time :</b></div>
        <div style="font-size:9px" id="insuranced"><b>Insurance :</b></div>
        <div style="font-size:9px" id="stopd"><b>Stop in Way :</b></div>

        <div style="font-size:9px" id="dis"><b>Distance(app) :</b></div>
        <div style="font-size:9px" id="tim"><b>Time(app) :</b></div>
        <div style="font-size:9px" id="ht"><b>PRICE (HT) :</b></div>
        <div style="font-size:9px" id="vat"><b>VAT :</b></div>
        <div style="font-size:9px" id="ttc"><b>PRICE (TTC) :</b></div>


<div style="text-align: center; font-style: italic;">Payment terms: payment due in 28 days</div>
</body>
</html>
';



$mpdf->WriteHTML($html);

$mpdf->Output(); exit;

exit;

?>

我已将遇到问题的代码加粗。

**<div style="font-size:9px" id="serviced"><b>Service :</b></div>
    <script type="text/javascript">
 $(document).ready(function(){
$("#serviced").load("http://website.com/service.php #serviced")
})
</script>**

我试图在上面的代码中加载 $html 内的 php 页面的 div 内容,但它没有加载。我已经尽了一切努力,但到目前为止还没有运气。

请帮我提供代码或建议。

谢谢!

最佳答案

查看文档:http://mpdf1.com/manual/index.php 不支持 JavaScript。

解析您的页面以检索您的#service(我可以建议您使用此解析器 http://simplehtmldom.sourceforge.net/ )

然后,只需在 HTML 中实现文本即可。

可以是这样的:

首先包含两个库:mpdf 和 simplehtmldom。

include("mpdf/mpdf.php");
include("simple_html_dom.php");

然后获得页面的正确部分:

$html     = file_get_html('http://yoururl.tld/');
$serviced = $html->find('div[id=serviced]', 0)->plaintext;

然后生成 PDF:

$mpdf = new mPDF('win-1252','A4','','',20,15,48,25,10,10);
... // Configure your PDF like you used to

$html  = '<your html before the #serviced part>';
$html .= $serviced;
$html .= '</your html after the #serviced part>';

$mpdf->WriteHTML($html);
$mpdf->Output();

还有tadaaaaa

关于php - mpdf 发票未按我想要的方式生成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12617493/

相关文章:

php - 在大型 PHP 框架之一之上编写的论坛/论坛

javascript - 如何使用 jQuery 实现从一张图片到另一张图片的过渡效果?

jquery - Bootstrap : Reducing NavBar width and all its drop down option panels and text size

jquery - 尝试使用 OR 逻辑将同位素过滤器与分页集成

php - 连接和转义字符后输出不完整

php - MySQL 3表搜索与一张不直接相关的表

php - 显示所有带有标签的博客

javascript - Python 脚本将用户名设为空

javascript - 如何为选项卡设置渐变颜色?

javascript - 根据用户计算机的性能禁用 JavaScript 功能