A
A
AleDv2017-05-25 14:59:00
Laravel
AleDv, 2017-05-25 14:59:00

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:
a4049ac11a2a4294aed916e68607d04f.PNG
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

3 answer(s)
S
Site Developer, 2017-05-25
@secsite

htmlbook.ru/html/a/download

C
chelkaz, 2017-05-26
@chelkaz

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 question

Ask a Question

731 491 924 answers to any question