Reputation: 855
I am trying to generate the pdf using mPdf - niklasravnsborg/laravel-pdf
in laravel 5.5. But every time I am getting the pdf in portrait mode.
public function showCertificate()
{
$data = [ 'name' => 'John Doe', 'prize' => '1st Prize'];
$pdf = PDF::loadView('certificates.show',
$data,
[],
[
'title' => 'Certificate',
'orientation' => 'L'
]);
return $pdf->stream('certificate.pdf');
}
Upvotes: 3
Views: 3766
Reputation: 666
Another subtle thing you may be missing if you encounter this same problem...take my case for example, I did not add the empty array syntax []
before the options/config array...
This will NOT work
public function showCertificate()
{
$data = [ 'name' => 'John Doe', 'prize' => '1st Prize'];
$pdf = PDF::loadView('certificates.show',
$data,
// [], I removed the emptyy arrayy
[
'title' => 'Certificate',
'format' => 'A4-L',
'orientation' => 'L'
]);
return $pdf->stream('certificate.pdf');
}
This will work
public function showCertificate()
{
$data = [ 'name' => 'John Doe', 'prize' => '1st Prize'];
$pdf = PDF::loadView('certificates.show',
$data,
[],
[
'title' => 'Certificate',
'format' => 'A4-L',
'orientation' => 'L'
]);
return $pdf->stream('certificate.pdf');
}
Take not of []
.
Upvotes: 0
Reputation: 855
I was finally able to get it resolved by using format
to A4-L
along with orientation
. My working code is given below.
public function showCertificate()
{
$data = [ 'name' => 'John Doe', 'prize' => '1st Prize'];
$pdf = PDF::loadView('certificates.show',
$data,
[],
[
'title' => 'Certificate',
'format' => 'A4-L',
'orientation' => 'L'
]);
return $pdf->stream('certificate.pdf');
}
I saw this issue and inferred from there to my answer.
Upvotes: 6