我能弄清楚,我工作的解决方案。它非常混乱,但它的工作原理
控制器
public function printPDF(Request $request)
{
$parts = Parts::all();
$date = $this->getTime();
// divide by 36 because I can fit 36 items on each page
$totalPages = ceil(count($parts)/36);
$pdf = SnappyPdf::loadView('parts.print.landscape', ["parts" => $parts, "date" => $date->toFormattedDateString(), "totalPages" => $totalPages])
->setOrientation('landscape')
->setPaper('a4');
}
}
HTML
@php
$count = 0;
$page = 0;
@endphp
PARTS ORIENTATION
@foreach ($parts as $part)
@php
// 36 is the total number of items I can fit on a page
// so after 36 I add a header and footer
if ($count === 36) {
echo '
echo '
PARTS ORIENTATION
';echo '
$count = 0;
$page++;
}
@endphp
alt="Error" width="127" height="127"/>
{{$part->text}}
@php
$count++;
if ($count == 36) {
// 36 is the total number of items I can fit on a page
// so after 36 I add a header and footer
$page = ($page == 0) ? 1 : $page;
echo '';
echo "
";echo "
";echo '';
}
elseif ($totalPages == $page) {
echo '';
echo "
";echo "
";echo '';
}
@endphp
@endforeach