编程语言
首页 > 编程语言> > php – 使用codeigniter和foreach循环的dompdf分页符

php – 使用codeigniter和foreach循环的dompdf分页符

作者:互联网

我使用codeigniter和dompdf生成pdf文档.

使用foreach循环生成文档.每个循环创建一些表行.我想在每个循环的行之间有一个分页符.

我的相关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>

我已经给了第一个第一类firstrow,我希望每次都能在此行之前出现分页符.

因此我在页面标题中应用了以下样式表:

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

这不起作用.

如何在每个循环第一次TR之前实现我想要的分页结果?

一如既往地谢谢

解决方法:

试试这个,我的报告完全一样

<?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 } ?>

(第一个< table>标记在循环内移动)

请尝试这个答案为header and footer.

标签:php,foreach,codeigniter,dompdf,page-break
来源: https://codeday.me/bug/20190612/1226760.html