首页 > 解决方案 > 由 DOMPDF 转为 PDF 的 HTML 表格

问题描述

我有一个数据库表包含一些信息,我正在检索 html 表中的表信息,我正在尝试将此表导出为 pdf 文件,我得到了???由于未知原因,在某些数字上,我使用的是 Xampp,PHP 版本 5.4。DomPdf 0.6 我将在下面分享我的代码:

     <?php
        $contentinvoice=
       '<html>
        <head>
            <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
            <style> body { font-family: Helvetica; font-size:10px; } </style>
        </head>
        <body>
        <table width="100%">
        <tr>
        <td>Code</td>
        <td>Description</td>
        <td>Quantity</td>
        <td>Price</td>
        </tr>';

        $select="SELECT * FROM invoicelines";
        $run=mysql_query($select,$con);
        if(!$run)die("Error".mysql_error());
        for($counter=1;$row=mysql_fetch_assoc($run);$counter++){

             $contentinvoice.=
               '<tr>
                    <td align="center">'.$row['code'].'</td>
                    <td align="center">'.$row['description'].'</td>
                    <td align="center">'.$row['quantity'].'</td>
                    <td align="center">'.$row['price'].'</td>
                </tr>';
        }

 $contentinvoice.='</table></body></html>';

 require_once("dompdf/dompdf_config.inc.php");

 $dompdf = new Dompdf();
 $dompdf->load_html(ob_get_clean());
 $dompdf->load_html($contentinvoice, 'UTF-8');
 $dompdf->set_paper('A4');
 $dompdf->render();
 $dompdf->stream("dompdf_out.pdf", array("Attachment" => false));

?>

我得到的结果与我需要的相同,但有些数字被替换为??? 喜欢

Code              Description              Quantity             Price
124?1231          Item 1                      ?                  ?.189
412?3123?         Item 2                      ?                  ?.234

注意:如果我在标题中将字体更改为 DejaVu Sans 符号?将转换为阿拉伯数字,例如 ?.189 将是١.189

标签: phppdfhtml-tableexportdompdf

解决方案


推荐阅读