2012-09-27 76 views
2

這是我用來生成pdf發票的編碼,我使用jquery在$ html中加載php頁面的div內容,但它根本不加載。我嘗試使用隱藏的字段和JavaScript,但沒有任何工作。不能生成我想要的mpdf發票

<?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;">0</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內容,但它不加載。我嘗試了所有我能做的,但迄今爲止沒有運氣。

請幫我提供代碼或建議。

謝謝!

+0

請幫我出同樣的問題 [http:// sta ckoverflow.com/q/25589922/2490365][1] – dinu1389

回答

3

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

解析你的頁面檢索您的#服務(我可以通知你這個解析器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

+0

看起來這是我正在尋找的答案,但我無法清楚地理解您的答案。我是PHP和MPF的新手,如果可能的話,你可以更詳細地解釋你的答案,如果你已經實現了類似的代碼,請與我分享。非常感謝您的幫助。 –

+0

我正在編輯我的帖子瞭解更多詳情 –

+1

而我完成了。請享用 –