I am using codeigniter and dompdf to generate a pdf document.
the document is generated with a foreach loop. 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:
<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>      <b>Order Number</b>: <font color='blue'>".$summary->OrderNum; ?>
<?php echo  "</font>      <b>Sales rep</b>: <font color='blue'>".$summary->RepName; ?>
<?php echo  "</font>      <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.
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?
Thanks as always
To make Pagebreak work with tr, write a line of css for tr
 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 =  "     ";
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)
Please try this answer for both header and footer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With