2014-08-31 53 views
1

MPDF使用MPDF

$html=' 
<body> 
<div id="page"> 
    <div id="logo"> 
    <a href="http://www.danifer.com/"><img src="./HTML Invoice Template_files/invoice_logo.jpg"></a> 
    </div><!--end logo--> 

    <div id="address"> 

    <p><strong>'.$company.'</strong><br> 
    <a href="mailto:'.$dbobj->getAdminEmail().'">'.$dbobj->getAdminEmail().'</a> 
    <br><br> 
    Transaction # xxx<br> 
    Created on 2008-10-09<br> 
    </p> 
    </div><!--end address--> 

    <div id="content"> 
    <p> 
     <strong>Customer Details</strong><br> 
     Name: '.$dbobj->UserFullName().'<br> 
     Email: '.$dbobj->UserEmail().'<br> 
     Contact: '.$dbobj->UserContact().'<br> 
     Payment Type: MasterCard </p> 
    <hr> 

    <table> 
     <tbody> 
     <tr> 
     <td><strong>Description</strong></td> 
     <td><strong>Qty</strong></td> 
     <td><strong>Unit Price</strong></td> 
     <td><strong>Amount</strong></td> 
     </tr> 
     <tr class="odd"> 
     <td>Product 1</td> 
     <td>1</td> 
     <td>Rs 1495.00</td> 
     <td>Rs 1495.00</td> 

     </tr> 
     <tr class="even"> 
     <td>Product 2</td> 
     <td>1</td> 
     <td>Rs 1495.00</td> 
     <td>Rs 1495.00</td> 
     </tr> 
     <tr class="odd"> 
      <td>Product 3</td> 
      <td>1</td> 
     <td>Rs 1495.00</td> 
     <td>Rs 1495.00</td> 
     </tr> 

     <tr> 
      <td>&nbsp;</td> 
      <td>&nbsp;</td> 
      <td><strong>Total</strong></td> 
      <td><strong>Rs 24485.00</strong></td> 
     </tr> 

    </tbody></table> 


    <hr> 
    <p> 
     Thank you for your order.<br> 
     If you have any questions, please feel free to contact us at <a href="mailto:'.$dbobj->getAdminEmail().'">'.$dbobj->getAdminEmail().'</a>. 
    </p> 

    <hr> 
    <p> 
     </p><center><small>This communication is for the exclusive use of the addressee and may contain proprietary, confidential or privileged information. If you are not the intended recipient any use, copying, disclosure, dissemination or distribution is strictly prohibited. 
     <br><br> 
     © '.$dbobj->sitename.' All Rights Reserved 
     </small></center> 
    <p></p> 
    </div><!--end content--> 
</div> 
</body>; 

拜託,我已經內嵌MPDF LIB在網站上創建動態發票賬單。
現在我想生成發票的動態pdf。
如何建立動態表格到$ html變量?然後我應該將它傳遞給的WriteHTML()

$mpdf->WriteHTML($html); 

然後,我將調用mpdf- $>輸出( '下載/應用.pdf', 'F');下載PDF

SQL PART

select desc,qty,price,total from orders where productid=1 

PHP PART

$mpdf=new mPDF(); 
$mpdf->SetDisplayMode('fullpage'); 
$mpdf->WriteHTML($html); 
$mpdf->Output('downloads/application.pdf','F'); 

我使用MySQL的

+0

更換所有的非動態行你是什麼意思的動態?您使用用戶填充它的表單而不是呈現PDF或某種數據庫結構? – HddnTHA 2014-08-31 07:59:56

+0

我必須從數據庫建表。 – dinu1389 2014-08-31 08:01:25

+0

對db進行查詢,並將它們打印到$ html變量中。順便說一句你的問題不清楚。我們無法幫助你減少細節。 – HddnTHA 2014-08-31 08:03:27

回答

2

我有我的手機來寫這個,所以代碼可能不完美。

使用foreach循環遍歷查詢結果構建$ htmlRows字符串。你沒有向我們展示你的php命令來查詢和結果變量。所以我假設$行爲一組記錄。

$htmlRows = ""; 
foreach($rows as $row) { 
    $htmlRows .= " 
     </tr> 
     <tr class="even"> 
     <td>".$row->desc."</td> 
     <td>".$row->qty."</td> 
     <td>Rs ".$row->price."</td> 
     <td>Rs ".$row->total."</td> 
     </tr> 
    "; 
} 

在生成$ html之前執行此循環。

然後,當你assing代碼$ HTML只是

​​
+1

我應該添加這樣的權利? $ HTML = 「.... .....」 。 $ htmlrows 。 「 ....」 ; – dinu1389 2014-08-31 08:39:49

+1

當然,....只是你在問你之前已經擁有的東西的地方。希望你現在可以自己搞清楚。 – 2014-08-31 09:11:57