Fatal error: Uncaught Error: Call to Undefined method Domprocessinginstruction::getattribute(). PHP AND DOMPDF

Asked

Viewed 344 times

0

I am trying to create a pdf with a table that receives php variable values.

The page runs perfectly, but when I use DOMPDF to create the pdf of the page it gives me the following error :

Fatal error: Uncaught Error: Call to undefined method DOMProcessingInstruction::getAttribute() in C:\xampp\htdocs\organizar\dompdf\src\Cellmap.php:554 Stack trace: #0 C:\xampp\htdocs\organizar\dompdf\src\Cellmap.php(518): Dompdf\Cellmap->add_frame(Object(Dompdf\FrameDecorator\Inline)) #1 C:\xampp\htdocs\organizar\dompdf\src\Cellmap.php(518): Dompdf\Cellmap->add_frame(Object(Dompdf\FrameDecorator\TableRowGroup)) #2 C:\xampp\htdocs\organizar\dompdf\src\FrameReflower\Table.php(532): Dompdf\Cellmap->add_frame(Object(Dompdf\FrameDecorator\Table)) #3 C:\xampp\htdocs\organizar\dompdf\src\FrameReflower\Table.php(408): Dompdf\FrameReflower\Table->get_min_max_width() #4 C:\xampp\htdocs\organizar\dompdf\src\FrameDecorator\AbstractFrameDecorator.php(895): Dompdf\FrameReflower\Table->reflow(Object(Dompdf\FrameDecorator\Block)) #5 C:\xampp\htdocs\organizar\dompdf\src\FrameReflower\Block.php(845): Dompdf\FrameDecorator\AbstractFrameDecorator->reflow(Object(Dompdf\FrameDecorator\Block)) #6 C:\xampp\htdocs\organizar\dompdf\src\FrameDecora in C:\xampp\htdocs\organizar\dompdf\src\Cellmap.php on line 554

Does anyone know what it might be?

The page is as follows :

<?php
session_start();
require '../../app/listadeferias.php';





?>


<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
<img src="../public/assets/logo.jpeg" style="width: 8%; margin: 0 30px;">

  <h1 style="text-align: center;"> Férias Marcadas </h1>  <table class="table" style="width: 100%; margin-bottom:40px; margin-top: 15px; ">
      <thead>
        <tr>
          <th scope="col">Data Inicial</th>
          <th scope="col">Data Final</th>
          <th scope="col">Numero de dias pedidos</th>
          <th scope="col">Ano referente</th>
          <th scope="col">Dias de férias disponiveis</th>
        </tr> 
        </thead>
         <tbody>
            <?php foreach ($resultado as $key => $value) {  ?>
         <tr>
         <th scope="col"><?= $value["dferiasinicial"]?></th>
          <th scope="col"><?= $value["dferiasfinal"]?></th>
          <th scope="col"><?= $value["ndias"]?></th>
          <th scope="col"><?= $value["ano"]?></th>
          <th scope="col"><?= $value["feriasrestantes"]?></th>
        </tr>
            <?php } ?>
      </tbody>
    </table>
</body>
</html>

Dompdf :

use Dompdf\Dompdf;

$document = new Dompdf();


$document-> loadHtml(file_get_contents('../public/pages/imprimepgina.php'));



$document->setPaper('A4', 'landscape');

$document->render();

$document->stream();

?>
  • Does this file path really exist? The error seems that it cannot load this file. $document-> loadHtml(file_get_contents('../public/pages/imprimepgina.php')); I say this because I use this library, The difference is that I built html on the same page and stored it in a variable.

  • There is, if I remove the part of the code where the foreach starts until it ends it creates a pdf with the beginning of the table

1 answer

1


In my case I made a string and stored all the html inside that string to make it work. Showing part of my code:

 foreach ($produtosTrocaPendente as $item):
                $html .="<tr style='font-size:12px;'>
                      <td class='col-sm-1'><img src='".$dominio.buscaFotoProduto($item['id_produto'])." style='width:100px;'></img>
                      </td>
                      <td class='col-md-3'>
                          <div class='form-group'>".$item['referencia']."</div>
                      </td>
                      <td class='col-md-5'>
                          <table>";
                          $produtoItemGrade = buscaTrocaPendenteGradeRelatorio($cliente,$item['id_produto']);
                              //tabela de grade de produtos
                              foreach ($produtoItemGrade as $produto_grade):

                              $html .="<td>
                                  <div class='form-group'>
                                      <div><kbd><label>
                                          ".$produto_grade['tamanho']."</label>
                                      </kbd><br>
                                          <b><label>".$produto_grade['pares']."</label></b>
                                      </div>
                                  </div>
                              </td>";
                            endforeach;
                          $html .="</table>
                        </td>
                        <td class='col-md-1'>
                            <div class='form-group'>".$item['preco']."</div>
                        </td>
                      <td class='col-md-1'>
                          <div class='form-group'>".$item['pares']."</div>
                      </td>
                      <td class='col-md-1'>
                          <div class='form-group'>".$item['valor']."</div>
                      </td>
                </tr>";
            endforeach;
        }
  $html .="</table>

At the end to load the PDF I associated the string:

$dompdf->loadHtml($html);

I don’t know if you solve your problem by doing so.

  • Yeah, I had to change a few things but that was the idea!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.