使用dompdf将html文件转换为pdf [英] convert html file to pdf using dompdf

查看:130
本文介绍了使用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);

?>

但是我得到这个错误:

 致命错误:调用未定义的方法Inline_Frame_Decorator :: normalize()在C:\wamp\www\pos\php\lib\dompdf\include\table_frame_decorator中。 252行的cls.php 

我该如何解决这个问题,请赐教。感谢。

更新
以下是checkout.html的内容

 < table border =0> 
< th colspan =10>产品< / th>
< th>数量< / th>
Price< th>
<! - < th>折扣< / th><! - 注释掉1月21日 - >
< th>小计< / th>





<! - 使用qtysoldfetcher查询从报告和prod_table中提取值 - >




< tr>
< td colspan =10> Boysen< / td>
< td> 4< / td>
< td> 900< / td>
<! - < td>< / td> - ><! - 注释掉1月21日 - >
< td> 3600< / td>
< / tr>









< tr>
< td>总帐单:< / td>
< td colspan =8> 3600< / td>

<! - - 新增jan 19 - >

< / tr>

< tr>

< td>付款金额:< / td>
< td colspan =8> 900< / td>
< / tr>



< tr>
< td>更改:< / td>
< td colspan =8>< / td>
< / tr>

< tr>
< td>贷:< / td>
< td colspan =8> 2700< / td>
< / tr>

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

< tr>
< td>购买者:< / td>
< td colspan =8>朝仓,Yoh< / td>
< / tr>
<! - end - >

< / table>


解决方案

checkout.html is有效?有没有表格和未关闭的标签?



Google群组有一个答案:


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


  2. 在元素$ b $中检查CSS中与表格相关的显示类型b表格结构尚未明确列出

  3. >

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

     <! - < th>折扣< / th><! - 注释掉1月21日 - > 

    第5行,第31列:无效注释声明:评论声明



    您的评论栏未关闭。您可以使用以下行:

     <! - < th>折扣< / th>  - >< ! - 注释掉1月21日 - > 


    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>
    

    解决方案

    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--> 
    

    这篇关于使用dompdf将html文件转换为pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆