I'm using DOMPDF library for made a prices list. I installed the library and try with simple pdf and all works ok. In my html template, i'm rendering data from a mysql table. This is my HTML :
<!-- Html pure code here-->
<?php for ($i=0; $i < count($products); $i++) { ?>
<section class="row">
<div class="col-md-4">
<h3><?=$products[$i]['codigo']?></h3>
</div>
<div class="col-md-8">
<h3><?=$products[$i]['titulo']?></h3>
</div>
</section>
<section class="row">
<div class="col-md-4">
<img src="<?=$products[$i]['img']?>" />
</div>
<div class="col-sm-8 data-producto">
<div class="descripcion">
<?=$products[$i]['descripcion']?>
</div>
<div class="precios">
<span class="precio">
</span>
</div>
</div>
</section>
<?php } ?>
And that's my controller code :
$categorias = $this->post('id_categoria');
$productos = new Modelos\Producto();
// This method make the query and return an array with data.
$products =
$productos->get(
['id_categoria'=>$categorias],
null,
'categoria asc,titulo asc'
);
//Helpers\Debug::imprimir($listadoProductos);
ob_start();
include 'Layout/electron/listado.tpl.php';
$html1 = ob_get_clean();
if (ob_get_length()) ob_end_clean();
$pdf = new Dompdf();
//exit($html1)
$pdf->loadHtml($html1);
$pdf->render();
$pdf->stream();
The error : The pdf takes a lot of time to be created. It takes up 3 minutes and sometimes simply it doesn't. If a print the pdf without the foreach loop. The pdf is created correctly. If y print only the html, without use dompdf, only in the navigator. the script run in a second. I need to do something more?
The products table has 45 products only.
Thanks.
The bug was because I was including bootstrap css file and DOMPDF does not support it correctly. Then I removed bootstrap and edit my file using a custom css and tables instead bootstrap's grid.
That's all.