convert html file to pdf using dompdf

2019-02-27 18:39发布

问题:

How do I properly use dompdf to convert html files into pdf. I'm doing something like this:

<?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");

?>

But I get this error:

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

How do I solve this, please enlighten me. Thanks.

Update Here are the contents of 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:

checkout.html is valid ? Is there any table and unclosed tags ?

There was an answer on Google Groups :

  1. check to see if you have any unclosed tags within the the table; DOMPDF can have trouble when your HTML isn't well-formed

  2. check for table-related display types in your CSS on elements where the table structure hasn't been explicitly outlined

UPDATE :

Your checkout.html file ISN'T valid. There is a problem :

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

Line 5, Column 31: invalid comment declaration: found name start character outside comment but inside comment declaration

Your comment block isn't closed. You can use this line :

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