[英]Error rendering data from database with dompdf
I'm using DOMPDF library for made a prices list. 我正在使用DOMPDF库制定价格清单。 I installed the library and try with simple pdf and all works ok. 我安装了该库,并尝试使用简单的pdf,并且一切正常。 In my html template, i'm rendering data from a mysql table. 在我的html模板中,我正在从mysql表中渲染数据。 This is my HTML : 这是我的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. 错误 :pdf需要花费大量时间才能创建。 It takes up 3 minutes and sometimes simply it doesn't. 它需要3分钟,有时甚至根本不需要。 If a print the pdf without the foreach loop. 如果打印的pdf没有foreach循环。 The pdf is created correctly. pdf已正确创建。 If y print only the html, without use dompdf, only in the navigator. 如果y仅在导航器中仅打印html,而不使用dompdf。 the script run in a second. 脚本在一秒钟内运行。 I need to do something more? 我需要做更多的事情吗?
The products table has 45 products only. 产品表仅包含45个产品。
Thanks. 谢谢。
The bug was because I was including bootstrap css file and DOMPDF does not support it correctly. 该错误是因为我包含了bootstrap css文件,而DOMPDF不正确地支持它。 Then I removed bootstrap and edit my file using a custom css and tables instead bootstrap's grid. 然后,我删除了引导程序,并使用自定义CSS和表格(而不是引导程序的网格)编辑文件。
That's all. 就这样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.