简体   繁体   English

使用codeigniter和foreach循环执行dompdf分页符

[英]dompdf page break with codeigniter and foreach loop

I am using codeigniter and dompdf to generate a pdf document. 我使用codeigniter和dompdf生成pdf文档。

the document is generated with a foreach loop. 使用foreach循环生成文档。 each loop creates a few table rows. 每个循环创建一些表行。 I want to have a pagebreak between the rows of each loop. 我想在每个循环的行之间有一个分页符。

my relevent codeigniter view syntax is: 我的相关codeigniter视图语法是:

<table width=100%>
<?php foreach($summary as $summary){  ?>
<tr class="firstrow">
<td colspan="10">
<?php echo  "<b>Customer</b>: <font color='blue'>".$summary->caccountname; ?>

<?php echo  "</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <b>Order Number</b>: <font color='blue'>".$summary->OrderNum; ?>

<?php echo  "</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <b>Sales rep</b>: <font color='blue'>".$summary->RepName; ?>

<?php echo  "</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <b>Due Date</b>: <font color='blue'>".substr($summary->DueDate,0,10); ?>
</td>
</tr>
<tr>
<td colspan="10"><hr>
</td>
</tr>
<tr>
<td colspan="10">

  <table class="sortable" width="90%">
  <tr><td ><b>Product</td><td ><b>Ordered</td><td ><b>Processed</td><td ><b>Outstanding</td><td ><b>Dispatched</td><td ><b>Available (incl FJ)</td><td ><b>Available FJ</td></tr>
  <?php foreach($$linedetails as $linedetails){  ?>
  <tr>
  <td><?php echo $linedetails->Product;  ?></td>
  <td><?php echo $linedetails->cubicvolume;  ?></td>
  <td><?php echo $linedetails->Processed;  ?></td>
  <td><?php echo $linedetails->Outstanding;  ?></td>
  <td><?php echo $linedetails->Dispatched;  ?></td>
  <td><?php echo $linedetails->TotalVolume;  ?></td>
  <td><?php echo $linedetails->FJVolume;  ?></td>
  </tr>
  <?php } ?>
  </table>
</td>
</tr>


<?php } ?>
</table>

I have given the first tr a class of firstrow , I would like a page break to appear before this line every time. 我已经给了第一个第一类firstrow ,我希望每次都能在此行之前出现分页firstrow

As such I have applied the following style sheet in my page header: 因此我在页面标题中应用了以下样式表:

<style>
 @media print
 {
 .firstrow {page-break-before:always}
 }
</style>

This doesnt work. 这不起作用。

How can I acheive my desired result of placeing a page break before each loop firstrow TR? 如何在每个循环第firstrow TR之前实现我想要的分页结果?

Thanks as always 一如既往地谢谢

To make Pagebreak work with tr , write a line of css for tr 要使Pagebreak与tr ,请为tr写一行css

 tr    { page-break-inside:avoid; page-break-after:auto }

Try above code. 试试上面的代码。

If not working, then add 如果不起作用,请添加

table { page-break-inside:auto }

Try this, I am doing reports exactly same way 试试这个,我的报告完全一样

<?php 
$nbsp5 =  "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";

foreach($summary as $summary) {  ?>
    <table width="100%" style="page-break-after:always;">
        <tr>
            <td colspan="10">
                <?php echo  "<b>Customer</b>: <font color='blue'>".$summary->caccountname; ?>
                <?php echo  "</font>".$nbsp5 ." <b>Order Number</b>: <font color='blue'>".$summary->OrderNum; ?>
                <?php echo  "</font>".$nbsp5 ." <b>Sales rep</b>: <font color='blue'>".$summary->RepName; ?>
                <?php echo  "</font>".$nbsp5 ." <b>Due Date</b>: <font color='blue'>".substr($summary->DueDate,0,10); ?>
            </td>
        </tr>
        <tr>
            <td colspan="10"><hr></td>
        </tr>
        <tr>
            <td colspan="10">
              <table class="sortable" width="90%">
                <tr>
                    <td><b>Product</b></td>
                    <td><b>Ordered</b></td>
                    <td><b>Processed</b></td>
                    <td><b>Outstanding</b></td>
                    <td><b>Dispatched</b></td>
                    <td><b>Available (incl FJ)</b></td>
                    <td><b>Available FJ</b></td>
                </tr>
              <?php foreach($$linedetails as $linedetails){  ?>
              <tr>
                  <td><?php echo $linedetails->Product;  ?></td>
                  <td><?php echo $linedetails->cubicvolume;  ?></td>
                  <td><?php echo $linedetails->Processed;  ?></td>
                  <td><?php echo $linedetails->Outstanding;  ?></td>
                  <td><?php echo $linedetails->Dispatched;  ?></td>
                  <td><?php echo $linedetails->TotalVolume;  ?></td>
                  <td><?php echo $linedetails->FJVolume;  ?></td>
              </tr>
              <?php } ?>
              </table>
            </td>
        </tr>

    </table>
<?php } ?>

(first <table> tag moved inside loop) (第一个<table>标签在循环内移动)

Please try this answer for both header and footer . 请尝试这个页眉和页脚的答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM