I’m using native PHP to generate a dynamic printout and have a foreach loop for items in the ‘tbody’. Is there a way to determine how many items each page when using window.print()?
<div class="row">
@foreach ($poData['po_details2'] as $detail)
<div style="border:solid 3pt;border-top: none;border-bottom:none;border-right:none;" class="col-sm-1">
<p class="s11" style="text-indent: 0pt;text-align: center;">
{!! $detail['stock_property_number'] !!}
</p>
</div>
<div style="border:solid 2pt;border-top: none;border-bottom:none;border-right:none;" class="col-sm-1">
<p class="s11" style="padding-left: 15pt;text-indent: 0pt;text-align: left;">
<p class="s11" style="text-indent: 0pt;text-align: center;">
</p>
</div>
<div style="border:solid 2pt;border-top: none;border-bottom:none;border-right:none;" class="col-sm-1">
<p class="s11 " style="text-indent: 0pt;text-align: center;">
{!! $detail['uom_acronym'] !!}
</p>
</div>
<div style="border:solid 2pt;border-top: none;border-bottom:none;border-right:none;" class="col-sm-4">
<div class="description" style="text-align: justify;">
{!! $detail['description'] !!}
</div>
<style>
ul,
ol {
list-style-position: outside;
margin-left: 20px;
}
.description {
text-align: justify;
}
ul ul,
ol ul,
ul ol,
ol ol {
margin-left: 20px;
}
.table {
margin-top: 10px;
/* Adjust spacing between content and table */
}
.table table {
border-collapse: collapse;
width: 100%;
}
.table table td {
border: 1px solid black;
/* Adjust table cell border */
padding: 5px;
/* Adjust table cell padding */
}
</style>
</div>
<div style="border:solid 2pt;border-top: none;border-bottom:none;border-right:none;" class="col-sm-1">
<p class="s11" style="text-indent: 0pt;text-align: center; ">
{!! intval($detail['quantity']) !!}
</p>
</div>
<div style="border:solid 2pt;border-top: none;border-bottom:none;border-right:none;" class="col-sm-2">
<p class="s11" style="padding-left: 11pt;text-indent: 0pt;text-align: left;">
<p class="s11" style="text-indent: 0pt;text-align: center; ">
<?php
$unitCost = floatval($detail['unit_cost']); // Convert to float, use intval() for integers
$formattedUnitCost = number_format($unitCost, 2, '.', ','); // Format with 2 decimal places, using comma as thousands separator and dot as decimal separator
echo $formattedUnitCost; // . ' P'Output the formatted unit cost
?>
</p>
</div>
<div style="border:solid 3pt;border-top: none;border-bottom:none; border-left:solid 2pt;" class="col-sm-2">
<p class="s11" style="padding-left: 9pt;text-indent: 0pt;text-align: left;">
<p class="s11" style="text-indent: 0pt;text-align: center; ">
<?php
$total_cost = $detail['total_cost']; // Assuming $detail['total_cost'] contains a numeric string
$numericValue = floatval($total_cost); // Convert to float, use intval() for integers
$formattedValue = number_format($numericValue, 2, '.', ','); // Format with 2 decimal places, using comma as thousands separator and dot as decimal separator
echo $formattedValue; // Output the formatted numeric value
?>
</p>
</div>
@endforeach
</div>
I’ve tried using JavaScript to calculate the number of items per page before triggering the print dialog, but I wasn’t successful.