2011-01-28 119 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-->