Unni K S
Unni K S

Reputation: 375

How to make a pdf report that automatically go to next page if column number exceeds the page width

How to automatically line-break if column numbers exceeds the page width.

Now the output showing like this Now the output showing like this

But i want the output like this

page 1: enter image description here

Page 2: enter image description here

I am using wkhtmltopdf and snappypdf wrapper.

Is there any native ways to solve this issue.

Upvotes: 0

Views: 1545

Answers (2)

rchatburn
rchatburn

Reputation: 752

I've just had to do something similar but over lines, i imagine the approach would work over columns just as effective.

first off create a css rule for pages

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

Then split the data by the number of columns that fit on a page, lets say 20 for now.

  @php
   $pages = array_chunk($dataArray, 20);
  @endphp

Now you can loop the number of pages you need to display

  @for ($i = 0; $i < count($pages); $i++)
        <div class="page">
          display your tables here
        </div>
  @endfor

This should dynamically generate the number of pages. if its the last page you probably want to do your column endings this can be done by taking comparing

@if($i+1 == count($pages))
 I am your last page
@endif

Hope it helps and gives you an idea how to tackle this

Upvotes: 0

Vinayak Kulkarni
Vinayak Kulkarni

Reputation: 291

Add this to your CSS.

thead {
  display: table-header-group;
}

tfoot {
  display: table-row-group;
}

tr {
  page-break-inside: avoid;
}

Upvotes: 0

Related Questions