Home > other >  How I can avoid this error on DOMPDF with laravel 8 when working with large tables?
How I can avoid this error on DOMPDF with laravel 8 when working with large tables?

Time:12-27

I am working with DOMPDF in Laravel 8, when I create a table with many records and jumps to the next page, it does not perform the page break as it should, Could someone help me to know what I am doing wrong?. I was reading many articles on the internet and none of them worked for me.

Here is my code:

<div >
  <table >
    <tbody>
      <tr>
        <td >{{ trans('image') }}</td>
        <td >{{ trans('just_name') }}</td>
        <td >{{ trans('quantity') }}</td>
        <td >{{ trans('unit_price') }}</td>
        <td >{{ trans('taxes') }}</td>
        <td >{{ trans('subtotal') }}</td>
        <td >{{ trans('total_price') }}</td>
      </tr>
      @for($i = 0; $i < 100; $i  )
        <tr>
          <td ><img src="{{ public_path('storage/uploads/products/d6d74f351d482bb41787e86350ace02e.jpg') }}" height="70px"></td>
          <td >PORTATIL DELL 4HWRT</td>
          <td >526</td>
          <td >$ 4.985.650</td>
          <td >$ 947.273,5</td>
          <td >$ 99.713.000</td>
          <td >$ 2.622.451.900</td>
        </tr>
      @endfor
    </tbody>
  </table>
</div>

Result: Go to screenshot (https://ibb.co/Rj5ZPTW)

CodePudding user response:

.page_break {
  page-break-before: always;
}
<!-- adjust $n as needed. $n = number of rows that fit in a page -->
@foreach(collect(range(1,100))->chunk($n) as $chunk)
  <div >
    <table >
      <tbody>
        <tr>
          <td >{{ trans('image') }}</td>
          <td >{{ trans('just_name') }}</td>
          <td >{{ trans('quantity') }}</td>
          <td >{{ trans('unit_price') }}</td>
          <td >{{ trans('taxes') }}</td>
          <td >{{ trans('subtotal') }}</td>
          <td >{{ trans('total_price') }}</td>
        </tr>
        @foreach($chunk as $i)
          <tr>
            <td ><img src="{{ public_path('storage/uploads/products/d6d74f351d482bb41787e86350ace02e.jpg') }}" height="70px"></td>
            <td >PORTATIL DELL 4HWRT</td>
            <td >526</td>
            <td >$ 4.985.650</td>
            <td >$ 947.273,5</td>
            <td >$ 99.713.000</td>
            <td >$ 2.622.451.900</td>
          </tr>
        @endforeach
      </tbody>
    </table>
  </div>
  <div ></div> <!-- break page -->
@endforeach
  • Related