I am creating a pdf in laravel which contains exactly 100 rows. Page break is working fine on the first page. But on the second page, it is working like in the screenshot. The new page is created but dont know what is happening with the data. My view file is as follows.
I tried adding a tr and inside the td tag put a div with style page-break, when the loop completes 20 iterations. Also, I tried to give page-break-inside: always for table, tr, and td. But nothing seems to work
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="generator" content="PDF">
<style>
body {
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
}
</style>
</head>
<body>
<div>
<?php
$company_name = explode(' ', $employee->company->title, '2');
$employee_name = getSalutation()[$employee->salutation] . '. ' . $employee->name . ' ';
if ($employee->middle_name !== null) {
$employee_name .= $employee->middle_name . ' ';
}
$employee_name .= $employee->last_name;
?>
<div style="padding: 10px;">
<table style="width: 100%">
<tr>
<td style="padding-bottom: 0px;">
<img src="<?php echo url('public_html/' . $employee->company->logo) ?>" width="80"
style="" alt="{{$employee->company->title}}">
<span style="font-size: 17px;"><?= $company_name[1] ?></span>
</td>
<td>
<span
style="display: block;float: right;font-size: 20px;font-weight: bold;text-transform: uppercase;">Loan/Salary Requests</span>
</td>
</tr>
<tr>
<td style="vertical-align: top;padding-bottom: 0px;">
<span style="display: block;font-size: 11px;"><?= $employee->company->address ?></span>
<span
style="display: block;font-size: 11px;"><?= $employee->company->address_line_2 ?></span>
<?php
//if($employee->company->telephone) {
?>
<span
style="display: block;font-size: 11px;">T: <?= $employee->company->telephone ?></span>
<?php
// }
?>
</td>
<td> </td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
</table>
</div>
@php
$moneyRequests = collect($moneyRequests)->groupBy('user_id');
@endphp
<table id="list">
<tr>
<td colspan="2">
<table style="width: 100%" align="center" border="0" cellpadding="0" cellspacing="0">
<thead>
<tr style="background-color: #2F2A74DA; color: #ffffff;">
<th style="border: 1px solid;padding: 3px;">Request Ref No</th>
<th style="border: 1px solid;padding: 3px;">Request Type</th>
<th style="border: 1px solid;padding: 3px;">Amount Requested Date</th>
<th style="border: 1px solid;padding: 3px;">Amount Taken</th>
<th style="border: 1px solid;padding: 3px;">Amount Repaid</th>
<!-- <th style="border: 1px solid;padding: 3px;">Total Amount Repaid</th> -->
<th style="border: 1px solid;padding: 3px;">Outstanding Amount</th>
</tr>
</thead>
<tbody>
@if(count($moneyRequests))
@php $i = 0; @endphp
@foreach($moneyRequests as $key => $moneyRequest)
<tr>
<td colspan="6"
style="border: 1px solid; padding: 4px;background-color: #d2d2d2;">{{$moneyRequest[0]->employee}}</td>
@php $i++; @endphp
</tr>
@php
$total_amount_given = $amount_repaid_till_date = $outstanding_amount = 0;
@endphp
@foreach($moneyRequest as $key1 => $req)
@php
$total_amount_given += str_replace(',','',$req->amount_given);
$amount_repaid_till_date += str_replace(',','',$req->amount_repaid_till_date);
$outstanding_amount += str_replace(',','',$req->outstanding_amount);
@endphp
@if($i >= 20)
@php $i = 0; @endphp
<!-- <tr>
<td colspan="6" style="page-break-inside: always;"> </td>
</tr> -->
@endif
<tr>
<td style="border: 1px solid; padding: 4px;width: 23%">{{$req->ref_no}}</td>
<td style="border: 1px solid; padding: 4px;width: 15%">{{$req->requestType}}</td>
<td style="border: 1px solid; padding: 4px;width: 15%">{{date('d-m-Y', strtotime($req->amount_requested_date))}}</td>
<td style="border: 1px solid; padding: 4px;">{{$req->amount_given}}</td>
<td style="border: 1px solid; padding: 4px;">{{$req->amount_repaid_till_date}}</td>
<!-- <td style="border: 1px solid; padding: 4px;">{{$req->total_amount_repaid}}</td> -->
<td style="border: 1px solid; padding: 4px;">{{$req->outstanding_amount}}</td>
@php $i++; @endphp
</tr>
@endforeach
<tr>
<td style="border: 1px solid; padding: 4px;" colspan="3">Total</td>
<td style="border: 1px solid; padding: 4px;"><b>{{number_format($total_amount_given, 2)}}</b></td>
<td style="border: 1px solid; padding: 4px;"><b>{{number_format($amount_repaid_till_date, 2)}}</b></td>
<td style="border: 1px solid; padding: 4px;"><b>{{number_format($outstanding_amount, 2)}}</b></td>
</tr>
@endforeach
@endif
</tbody>
</table>
</td>
</tr>
</table>
</div>
</body>
</html>
Hope someone can help me!!