【问题标题】:codeigniter dompdf page break issue during maximum table records最大表记录期间的codeigniter dompdf分页问题
【发布时间】:2018-04-04 00:02:29
【问题描述】:

对于有限的表格记录 pdf 看起来不错。

“echo $html”中的所有表格记录看起来都不错,但是在创建 pdf 后,当表格记录达到最大值时,分页符不起作用。它会在最多记录期间创建前 4-5 页空白。

最大表记录期间的codeigniter dompdf分页问题:

我的代码sn-p:

//控制器代码

function pdf_create($html, $filename='', $stream=TRUE) 
    {
        require_once("dompdf/dompdf_config.inc.php");

        $dompdf = new DOMPDF();
        $dompdf->load_html($html);
        $dompdf->render();
        if ($stream) {
            $dompdf->stream($filename.".pdf");
        } else {
            return $dompdf->output();
        }
    }

//查看文件代码

    ......
       ......  
        <tr>
                <td>
              <table width="100%" border="0" style="border:solid 1px #BFBFBF; page-break-inside: auto;" cellspacing="0" cellpadding="10">
       <tr bgcolor="#BFBFBF">
        <td><p style="font-size:14px; margin:0px;">Product Name</p></td>
        <td><p style="font-size:14px; margin:0px;">Product Quantity</p></td>
        <td><p style="font-size:14px; margin:0px;">Product Price</p></td>
        <td><p style="font-size:14px; margin:0px;">Total Price</p></td>
      </tr>
      <?php
$product_title = $product_details['product_titles'];
$prod_quantity = $product_details['product_qty'];
$price = $product_details['product_price'];
$total_price = $product_details['product_cal_price'];
$i = 1;
$j = 0;
$productwisetotal = 0;
foreach ($product_title as $value) { $productwisetotal += $value; ?>      
          <tr style="font-size:12px;" valign="top">
              <td style="border-right:solid 1px #BFBFBF"><?php echo $i.'. '.$value; ?></td>
              <td style="border-right:solid 1px #BFBFBF"><?php echo $prod_quantity[$j]; ?></td>
              <td style="border-right:solid 1px #BFBFBF"></td>
              <td style="border-right:solid 1px #BFBFBF"></td>
          </tr>
<?php    $i++;
         $j++;
       } ?>      
    </table>  

                </td>    
                </tr>
        .....
        .....

请告诉我,当表格包含最大记录时,如何在 pdf 中添加分页符??

【问题讨论】:

    标签: php codeigniter pdf codeigniter-2 dompdf


    【解决方案1】:

    为父表添加page-break-inside: auto,如下所示

    <table style="page-break-inside: auto">
    <tr>
    <td>
    
    <table width="100%" border="0" style="border:solid 1px #BFBFBF;" cellspacing="0" cellpadding="10">
           <tr bgcolor="#BFBFBF">
    -------
    </table>
    

    【讨论】:

    • 但我的父表不在 foreach 中.. 嵌套表在那里.. 我可以将它应用于 吗?请建议更改我的代码?
    • page-break-inside: auto 是添加分页符的最佳方式。你能在 tr 或 table 上试试吗
    猜你喜欢
    相关资源
    最近更新 更多
    热门标签