Reputation: 6435
I am using laravel-snappy
in my Laravel project to generate PDF files from View templates. This package uses wkhtmltopdf.
I am trying to set some headers and footers when I generate the PDF in my routes file like this:
Route::get('/statement-of-fact', function () {
$pdf = PDF::loadView('pdf.statement-of-fact');
$footer = resource_path('views/pdf/statement-of-fact-footer.html');
$pdf->setOption('footer-html', $footer);
return $pdf->stream();
})->name('statement-of-fact');
The PDF generates fine but the footer is never rendered.
What am I doing wrong here?
My HTML file:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div class="row">
<div class="col-xs-12">
Hello
</div>
</div>
</body>
</html>
Upvotes: 2
Views: 7252
Reputation: 9693
On
$pdf->setOption('footer-html', $footer);
$footer should be route to footer and not to path of footer, so it should be something like
Route::get('pdf-footer', function(){
return view('nova::pdf-partials.footer');
})->name('pdf.footer');
and
$pdf->setOption('footer-html', route('pdf.footer'));
Upvotes: 0
Reputation: 1929
You should try to load the footer this way:
$pdf = PDF::loadView('path.to.your.pdf.view');
$pdf->setOption('footer-html', view('path.to.your.footer'));
return $pdf->inline();
And in your config/snappy.php
set some margins:
'pdf' => array(
// ...
'options' => array(
'margin-top' => 15,
'margin-right' => 10,
'margin-bottom' => 15,
'margin-left' => 10,
),
),
Upvotes: 2