【问题标题】:DOMPDF, brings me an errorDOMPDF,给我带来一个错误
【发布时间】:2013-02-17 08:05:54
【问题描述】:

这是我在 PdfHtml 类中的代码:

public function createTable($result){

    $html = "<html>
                    <body>
                        <table>
                            <th>
                                <td>Descripción</td>
                                <td>Artículo</td>
                                <td>Precio</td>
                            </th>
                        ";
    while($row = mysql_fetch_array($result)){
        $html .= "<tr>";
        $html .= "<td>".$row["producto"]."</td>";
        $html .= "<td>".$row["idProducto"]."</td>";
        $html .= "<td>".$row["precio"]."</td>";
        $html .= "</tr>";
    }

    $html .= "</table>
                </body>
                    </html>";

    return $html;
}
</i>

我正在执行以下操作:

$pdfHtml = new PdfHTML();
$result = $pdfHtml->getProductosPorMarca($idMarca);
$html = $pdfHtml->createTable($result);

$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->output();

然后扔这个:

Catchable fatal error: Argument 1 passed to DOMNode::appendChild() must be an instance of DOMNode, null given, called in /opt/lampp/htdocs/ONLINE/dompdf0.6/include/table_frame_decorator.cls.php on line 304 and defined in /opt/lampp/htdocs/ONLINE/dompdf0.6/include/frame.cls.php on line 726

请帮帮我,我没有发现我的错误在哪里!!!谢谢!!

【问题讨论】:

    标签: php html mysql dompdf


    【解决方案1】:

    使用单引号 (' '),像这样:

    public function createTable($result){
      $html = '<html>
                    <body>
                        <table>
                            <th>
                                <td>Descripción</td>
                                <td>Artículo</td>
                                <td>Precio</td>
                            </th>';
    
    
      while($row = mysql_fetch_array($result)){
        $html .= "<tr>";
        $html .= "<td>".$row["producto"]."</td>";
        $html .= "<td>".$row["idProducto"]."</td>";
        $html .= "<td>".$row["precio"]."</td>";
        $html .= "</tr>';
      }
    
      $html .= '</table>
                </body>
                </html>';
    
      return $html;
    }
    

    【讨论】:

      【解决方案2】:

      基本

      元素:
      $html = "<html>
                          <body>
                              <table>
                                  <tr>
                                      <th>Descripción</th>
                                      <th>Artículo</th>
                                      <th>Precio</th>
                                  </tr>
                              ";
      

      【讨论】:

        【解决方案3】:

        您的 HTML 是问题的根源。您在 TH 元素中嵌套了一堆 TD 元素,但这无效。容器应该仍然是一个 TR 元素;单个单元格将是 TH 元素。如果你想要一个跨页重复的表头,你可以将表头行嵌套在 THEAD 元素中,将表体嵌套在 TBODY 元素中。

        【讨论】:

        • 我为此更改了 html 代码,并给我带来了这个:致命错误:调用 /opt/lampp/htdocs/ONLINE/dompdf0.6/include/cellmap 中未定义的方法 DOMText::getAttribute() .cls.php 在第 399 行。你有例子吗?谢谢
        • 更新的代码示例将有助于弄清楚您的代码发生了什么。您可能还想尝试验证您的代码生成的 HTML:validator.w3.org
        猜你喜欢
        • 2011-08-25
        • 2021-10-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-09-21
        • 2015-12-19
        相关资源
        最近更新 更多