doukunsan5553 2017-04-25 01:36
浏览 64
已采纳

使用dompdf从数据库呈现数据时出错

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.

  • 写回答

1条回答 默认 最新

  • donglu1973 2017-05-11 13:29
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号