Answer the question
In order to leave comments, you need to log in
How to give a PDF for download?
Hello. I'm trying to give a pdf file generated on the fly to the user, but the file is output as a string to the browser. The desired headers are sent.
Source: laravel 5, barryvdh/laravel-dompdf package for generating pdf. I get this rubbish:
The whole process is this: there is a form with a button and hidden fields (id for the model). In the controller I process the form:
$pdf = \App::make('dompdf.wrapper');
$pdf->loadView('pdf.offer', [ 'offer' => $offer ]);
return $pdf->download(str_slug($offer->title . '_' . $offer->id).'.pdf');
Answer the question
In order to leave comments, you need to log in
Add headers:
$pdf = \App::make('dompdf.wrapper');
$pdf->loadView('pdf.offer', [ 'offer' => $offer ]);
header("Content-type:application/pdf");
header("Content-Disposition:attachment;filename=".str_slug($offer->title . '_' . $offer->id).'.pdf');
return $pdf->download(str_slug($offer->title . '_' . $offer->id).'.pdf');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question