laravel-dompdf: how can i use page-break-after: always; for table in laravel ?

im getting error so if i use page-break i can solve this but i don’t know how to use i tried many way but it won’t work

DOMPDF_Exception in cellmap.cls.php line 244:
Frame not found in cellmap

My method -

public function invoice($id){
        $job = Job::find($id);
        $sum = DB::table('charges')
            ->where('job_id', $job->id)
            ->sum('amount');
        $charges = Charge::select('charges.*','consignees.name')
            ->leftJoin('jobs','jobs.id','=','charges.job_id')
            ->leftJoin('consignees','consignees.id','=','jobs.consignee_id')
            ->where('job_id', $job->id)
            ->get();
        $invoice = DB::table('jobs')
            ->where('id',$id)
            ->sum('invoice_value');
        $total = $sum - $invoice ;
        $pdf = \PDF::loadView('jobs.invoice',compact('job','sum','charges','total'));
        return $pdf->download('invoice.pdf');
    }

my invoice -

 <tbody>
        <?php $i=0 ?>
        @foreach($charges as $expense)
            <?php $i++ ?>
            <tr>

                <td class="id">{!! $expense->id !!}</td>
                <td class="date">{!! $expense->date!!}</td>
                <td class="charge">{!! $expense->charge!!}</td>
                <td class="cat">{!! $expense->category!!}</td>
                <td class="amount">{!! $expense->amount!!}</td>

            </tr>

        @endforeach
        <tr>
            <td colspan="4">TOTAL EXPENSES</td>
            <td class="total">{!!  $sum !!}</td>
        </tr>
        <tr>
            <td colspan="4">INVOICE VALUE</td>
            <td class="total">{!! $job->invoice_value!!}</td>
        </tr>
 </tbody>

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 19

Most upvoted comments

Pravansik,

I share to you on how it will break nicely and cleanly:

if( $i % 10 == 0 ){ echo '<div class="breakNow"></div>'; .... }

In your css code:

div.breakNow { page-break-inside:avoid; page-break-after:always; }

I break the table on every 10, you can customize it in your own 😃

@kapilpaul if you installed laravel-dompdf then create view file in view path resource/view/invoice.blade.php then paste this code

<!DOCTYPE html>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<style>
.page-break {
    page-break-after: always;
}
</style>
<body>

<h1>Page 1</h1>
<div class="page-break"></div>
<h1>Page 2</h1>

</body>
</html>

your route like this Route::get('/invoice', 'HomeController@createInvoice'); in your HomeController

public function createInvoice() {
$pdf = \PDF::loadView('invoice');
return $pdf->download('invoice.pdf');
}

this is basic try and let me know

This is the way to use page break. if you show your code can try to help you

<style>
.page-break {
    page-break-after: always;
}
</style>
<h1>Page 1</h1>
<div class="page-break"></div>
<h1>Page 2</h1>