Add page numbers to PDFs, fixes #39
This commit is contained in:
@@ -76,24 +76,43 @@ public function preview($id)
|
||||
'isPDF' => false,
|
||||
'fontPath' => '/storage/fonts',
|
||||
'giroCode' => $giroCode,
|
||||
'totalPages' => 1
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// https://www.itsolutionstuff.com/post/laravel-dompdf-table-with-page-break-exampleexample.html
|
||||
public function exportPdf($id)
|
||||
{
|
||||
$invoice = self::single($id);
|
||||
$giroCode = $this->generateGiroCode($invoice['totalAmount'], $invoice['nr'], $invoice['title']);
|
||||
|
||||
$pdf = Pdf::loadView('invoice', [
|
||||
$viewData = [
|
||||
'invoice' => $invoice,
|
||||
'isPDF' => true,
|
||||
'fontPath' => public_path('storage/fonts/'),
|
||||
'giroCode' => $giroCode,
|
||||
]);
|
||||
$pdf->setOption(['isRemoteEnabled' => true]);
|
||||
$pdf->setOption(['fontDir' => public_path('storage/fonts/')]);
|
||||
$pdf->setOption(['fontCache' => public_path('storage/fonts/')]);
|
||||
'totalPages' => 1
|
||||
];
|
||||
|
||||
$options = [
|
||||
'isRemoteEnabled' => true,
|
||||
'fontDir' => public_path('storage/fonts/'),
|
||||
'fontCache' => public_path('storage/fonts/')
|
||||
];
|
||||
|
||||
$pdf = Pdf::loadView('invoice', $viewData);
|
||||
$pdf->setOptions($options, true);
|
||||
$pdf->render();
|
||||
|
||||
// if there’s more than one page, inject page number an render again
|
||||
// https://github.com/dompdf/dompdf/issues/1636
|
||||
$viewData['totalPages'] = $pdf->getCanvas()->get_page_count();
|
||||
if ($viewData['totalPages'] > 1) {
|
||||
$pdf = Pdf::loadView('invoice', $viewData);
|
||||
$pdf->setOptions($options, true);
|
||||
}
|
||||
|
||||
return $pdf->stream($invoice['nr'] . '.pdf');
|
||||
// return $pdf->download($this->getFilename($invoice) . '.pdf');
|
||||
|
||||
@@ -43,7 +43,6 @@
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<!-- Fixed page elements need to bee direct descendents of body for Dompdf -->
|
||||
<!-- see https://github.com/dompdf/dompdf/issues/1190 -->
|
||||
<img id="logo"
|
||||
@@ -201,6 +200,10 @@
|
||||
Stadtsparkasse Augsburg, DE40 7205 0000 0251 5125 13, BIC AUGSDE77XXX, Ust-IdNr. DE309558315
|
||||
</footer>
|
||||
|
||||
<pagination>
|
||||
Seite <span class="page-number"></span> / {{ $totalPages }}
|
||||
</pagination>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user