使用dompdf将html文件转换为pdf

时间:2011-01-28 15:20:42

标签: php html pdf dompdf

如何正确使用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>

1 个答案:

答案 0 :(得分:4)

checkout.html 有效吗?有没有桌子和未封闭的标签?

Google网上论坛有一个答案:

  1. 检查表格中是否有任何未关闭的标签; 当HTML格式不正确时,DOMPDF会遇到麻烦

  2. 检查CSS中元素的表格相关显示类型 表结构尚未明确概述

  3. 更新:

    您的checkout.html文件无效。有一个问题:

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

    第5行,第31栏:无效的评论声明:在评论之外找到了姓名开始字符,但在评论声明中

    您的评论区块未关闭。你可以使用这一行:

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