Home  >  Q&A  >  body text

Laravel + mpdf implements automatic paging function

If the data exceeds 10, I try to auto-paginate, I use mpdf laravel vue

This is my CSS code

<style>
div.breakNow { page-break-inside:avoid; page-break-after:always; }
</style>

This is my sale_pdf.blade.php

$i=0;
         @foreach ($details as $detail)
         $i++;
         if( $i % 10 == 0 ){

<div class="breakNow">
             <div id="details_inv">
                <table  class="table-sm">
                   <thead>
                      <tr>
                         <th>PRODUCT</th>
                         <th>UNIT PRICE</th>
                         <th>QUANTITY</th>
                         <th>DISCOUNT</th>
                         <th>TAX</th>
                         <th>TOTAL</th>
                      </tr>
                   </thead>
                   <tbody>
    
                
                      <tr>
                         <td>{{$detail['code']}} ({{$detail['name']}})</td>
                         <td>{{$detail['price']}} </td>
                         <td>{{$detail['quantity']}}/{{$detail['unitSale']}}</td>
                         <td>{{$detail['DiscountNet']}} </td>
                         <td>{{$detail['taxe']}} </td>
                         <td>{{$detail['total']}} </td>
                      </tr>
                   }  @endforeach
                   </tbody>
                </table>
             </div>
           </div>

This is the current output.

Did I miss something? Thank you in advance

P粉164942791P粉164942791229 days ago324

reply all(1)I'll reply

  • P粉489081732

    P粉4890817322024-03-28 11:49:15

    There are two ways to solve this problem.

    Option 1

    
    
    
    
    
    
    

    Page 1

    Page 2

    Option 2 Add class

    between table rows
    $i=0;
    @foreach ($details as $detail)
      $i++;
    
    
    @endforeach

    reply
    0
  • Cancelreply