在使用大型表格时,如何在带有 laravel 8 的 DOMPDF 上避免此错误?
How I can avoid this error on DOMPDF with laravel 8 when working with large tables?
我在 Laravel 8 中使用 DOMPDF,当我创建一个包含许多记录的 table 并跳转到下一页时,它没有按应有的方式执行分页符,有人可以帮忙吗我知道我做错了什么?我在互联网上阅读了很多文章,其中 none 对我有用。
这是我的代码:
<div class="box-products-table">
<table class="table table-striped table-bordered">
<tbody>
<tr>
<td class="text-center roboto">{{ trans('image') }}</td>
<td class="text-center roboto">{{ trans('just_name') }}</td>
<td class="text-center roboto">{{ trans('quantity') }}</td>
<td class="text-center roboto">{{ trans('unit_price') }}</td>
<td class="text-center roboto">{{ trans('taxes') }}</td>
<td class="text-center roboto">{{ trans('subtotal') }}</td>
<td class="text-center roboto">{{ trans('total_price') }}</td>
</tr>
@for($i = 0; $i < 100; $i++)
<tr>
<td class="text-center"><img src="{{ public_path('storage/uploads/products/d6d74f351d482bb41787e86350ace02e.jpg') }}" height="70px"></td>
<td class="text-center">PORTATIL DELL 4HWRT</td>
<td class="text-right">526</td>
<td class="text-right">$ 4.985.650</td>
<td class="text-right">$ 947.273,5</td>
<td class="text-right">$ 99.713.000</td>
<td class="text-right">$ 2.622.451.900</td>
</tr>
@endfor
</tbody>
</table>
</div>
.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 class="box-products-table">
<table class="table table-striped table-bordered">
<tbody>
<tr>
<td class="text-center roboto">{{ trans('image') }}</td>
<td class="text-center roboto">{{ trans('just_name') }}</td>
<td class="text-center roboto">{{ trans('quantity') }}</td>
<td class="text-center roboto">{{ trans('unit_price') }}</td>
<td class="text-center roboto">{{ trans('taxes') }}</td>
<td class="text-center roboto">{{ trans('subtotal') }}</td>
<td class="text-center roboto">{{ trans('total_price') }}</td>
</tr>
@foreach($chunk as $i)
<tr>
<td class="text-center"><img src="{{ public_path('storage/uploads/products/d6d74f351d482bb41787e86350ace02e.jpg') }}" height="70px"></td>
<td class="text-center">PORTATIL DELL 4HWRT</td>
<td class="text-right">526</td>
<td class="text-right">$ 4.985.650</td>
<td class="text-right">$ 947.273,5</td>
<td class="text-right">$ 99.713.000</td>
<td class="text-right">$ 2.622.451.900</td>
</tr>
@endforeach
</tbody>
</table>
</div>
<div class="page-break"></div> <!-- break page -->
@endforeach
我在 Laravel 8 中使用 DOMPDF,当我创建一个包含许多记录的 table 并跳转到下一页时,它没有按应有的方式执行分页符,有人可以帮忙吗我知道我做错了什么?我在互联网上阅读了很多文章,其中 none 对我有用。
这是我的代码:
<div class="box-products-table">
<table class="table table-striped table-bordered">
<tbody>
<tr>
<td class="text-center roboto">{{ trans('image') }}</td>
<td class="text-center roboto">{{ trans('just_name') }}</td>
<td class="text-center roboto">{{ trans('quantity') }}</td>
<td class="text-center roboto">{{ trans('unit_price') }}</td>
<td class="text-center roboto">{{ trans('taxes') }}</td>
<td class="text-center roboto">{{ trans('subtotal') }}</td>
<td class="text-center roboto">{{ trans('total_price') }}</td>
</tr>
@for($i = 0; $i < 100; $i++)
<tr>
<td class="text-center"><img src="{{ public_path('storage/uploads/products/d6d74f351d482bb41787e86350ace02e.jpg') }}" height="70px"></td>
<td class="text-center">PORTATIL DELL 4HWRT</td>
<td class="text-right">526</td>
<td class="text-right">$ 4.985.650</td>
<td class="text-right">$ 947.273,5</td>
<td class="text-right">$ 99.713.000</td>
<td class="text-right">$ 2.622.451.900</td>
</tr>
@endfor
</tbody>
</table>
</div>
.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 class="box-products-table">
<table class="table table-striped table-bordered">
<tbody>
<tr>
<td class="text-center roboto">{{ trans('image') }}</td>
<td class="text-center roboto">{{ trans('just_name') }}</td>
<td class="text-center roboto">{{ trans('quantity') }}</td>
<td class="text-center roboto">{{ trans('unit_price') }}</td>
<td class="text-center roboto">{{ trans('taxes') }}</td>
<td class="text-center roboto">{{ trans('subtotal') }}</td>
<td class="text-center roboto">{{ trans('total_price') }}</td>
</tr>
@foreach($chunk as $i)
<tr>
<td class="text-center"><img src="{{ public_path('storage/uploads/products/d6d74f351d482bb41787e86350ace02e.jpg') }}" height="70px"></td>
<td class="text-center">PORTATIL DELL 4HWRT</td>
<td class="text-right">526</td>
<td class="text-right">$ 4.985.650</td>
<td class="text-right">$ 947.273,5</td>
<td class="text-right">$ 99.713.000</td>
<td class="text-right">$ 2.622.451.900</td>
</tr>
@endforeach
</tbody>
</table>
</div>
<div class="page-break"></div> <!-- break page -->
@endforeach