2011-01-28 49 views
1

如何正確使用dompdf將html文件轉換爲pdf。我在做這樣的事情:使用dompdf將html文件轉換爲pdf

<?php 
require_once("lib/dompdf/dompdf_config.inc.php"); 

$file = "checkout.html"; 

$dompdf = new DOMPDF(); 
$dompdf->load_html_file($file); 
$dompdf->render(); 
$dompdf->stream("sample.pdf"); 

?> 

但我得到這個錯誤:

Fatal error: Call to undefined method Inline_Frame_Decorator::normalise() in C:\wamp\www\pos\php\lib\dompdf\include\table_frame_decorator.cls.php on line 252 

我該如何解決這個問題,請賜教。謝謝。

更新 這裏是checkout.html的內容

<table border="0"> 
    <th colspan="10">Product</th> 
    <th>Quantity</th> 
    <th>Price</th> 
    <!--<th>Discount</th><!-- commented out jan 21--> 
    <th>Subtotal</th> 





     <!-- fetch values from reports and prod_table using the qtysoldfetcher query--> 




<tr> 
<td colspan="10">Boysen</td> 
<td>4</td> 
<td>900</td> 
<!-- <td></td> --><!-- commented out jan 21--> 
<td>3600</td> 
</tr> 








<h3 id="wyt">Sales Transaction Summary</h3><a href="pdfqtysold.php"><img id="tablez" src="../img/system/icons/Oficina-PDF-icon.png"></img></a> 

<tr> 
<td>Total Bill: </td> 
<td colspan="8">3600</td> 

<!--added jan 19 --> 

</tr> 

<tr> 

<td>Amount paid: </td> 
<td colspan="8">900</td> 
</tr> 



<tr> 
<td>Change: </td> 
<td colspan="8"></td> 
</tr> 

<tr> 
<td>Credit: </td> 
<td colspan="8">2700</td> 
</tr> 

<tr> 
<td>Date: </td> 
<td colspan="8">2011-01-28 11:13:52</td> 
</tr> 

<tr> 
<td>Bought by: </td> 
<td colspan="8">Asakura, Yoh</td> 
</tr> 
<!--end--> 

</table> 
+0

我更新了我的答案。你可以檢查。 – Eray 2011-01-28 15:59:11

+0

你的html仍然是可怕的結構。 dompdf在處理結構問題時有一定的靈活性,但不是*那麼多。以下文檔(基於您自己的)將正確呈現:http://eclecticgeek.com/dompdf/debug_tests/so4829828.htm – BrianS 2011-02-02 18:55:08

回答

4

checkout.html是有效的?有沒有表格和未封閉的標籤?

有在谷歌論壇的答案:

  1. 檢查,看看是否有表內的任何未關閉的標籤; DOMPDF可以有麻煩時,你的HTML是沒有很好地形成

  2. 爲表相關的顯示類型檢查你的CSS上所在的表結構沒有被明確列出的元素

更新:

您的checkout.html文件無效。這裏有一個問題:

<!--<th>Discount</th><!-- commented out jan 21--> 

5行,第31列:無效評論聲明:找到名字起始字符以外的評論,但評論聲明

你的註釋塊未關閉內。您可以使用此行:

<!--<th>Discount</th>--><!-- commented out jan 21-->