Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

barryvdh/laravel-dompdf page break content changes PDF

I am using this package barryvdh/laravel-dompdf is there any way to detect if content fits on the current page if not I want to put that content to the next page if it does not fit completly.

like image 925
shkurta Avatar asked Oct 13 '17 11:10

shkurta


1 Answers

This is said in the documentation about the asked subject: https://github.com/barryvdh/laravel-dompdf

Tip: Page breaks

You can use the CSS page-break-before/page-break-after properties to create a new page.

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

Update, you can iterate through the items and call for example after 10 divs:

<?php $i=0 ?>
@foreach($array as $object)
<?php $i++ ?>
    <!-- do something here | divs -->
    if( $i % 10 == 0 ){ 
        echo '<div class="page-break"></div>'; .... 
    }
@endforeach

You will have to determine yourself how many divs you can show to fill a page. An A4 paper for example has always the same height so you could make a guess of how many of your divs can be displayed on this page.

like image 80
Lars Mertens Avatar answered Oct 31 '22 21:10

Lars Mertens