Reputation: 116
The issue I'm having may be implementation but I can't find any consistency between PDFs which download correctly and those which return no response data.
I'm using Laravel v5.4.36 and v0.4.0 of Snappy.
I'm using Angular 5 on the front-end. Any requests for PDFs are setting responseType:3 (Blob). The issue isn't how Angular interprets the data, it's that no data is returned when generating some PDFs.
Here are things I've tried to get something to return when using $pdf->download
or $pdf->stream
:
<h1>Hello World</h1>
and I get the same result (nothing) that I would from outputting my multi-page HTMLsave()
the PDF it is generated correctly and I can view it without issuePDF::loadView('pdfs.reminder', compact('transactions', 'globalData'))
and \View::make('pdfs.reminder', compact('transactions', 'globalData'))
to generate the HTML. That doesn't have any effect.Here is the code I'm currently using:
private function generatePDF($transactions, $globalData)
{
$html = \View::make('pdfs.reminder', compact('transactions', 'globalData'))->render();
$pdf = \PDF::loadHTML($html);
return $pdf->download('reminder.pdf');
}
It's also worth noting that some PDFs I've tried to generate have worked. But that is a 1/3 success ratio so far. I'm using the same request format and same methods for all 3. No errors are being thrown.
My suspicion was that perhaps it's the size of the generated PDF which is causing the download to fail. However, I don't imagine that being an issue in a PDF that only contains <h1>Hello World</h1>
. Are there any limitations in terms of filesize which could cause this behaviour?
Any help with this is appreciated.
The issue wasn't with Snappy it was that the method which called generatePDF
didn't return generatePDF
's result. Hence why nothing was returned. As that bit of code wasn't in my question it was near impossible for anyone else to help. Thanks to all who tried though.
Upvotes: 2
Views: 3563
Reputation: 1005
E.g
$date = Carbon::now()->format('j F, Y');
$application = Application::find($id);
$data = ['date'=>$date,'application'=>$application]; // data to be passes to view file
$pdf = PDF::loadView('pdfs.reminder', $data)->setPaper('a4');
return $pdf->download('reminder.pdf');
Note: Make sure you have use the PDF Class (use PDF;
) before the class begins.
Upvotes: 2
Reputation: 212
Do you have <!DOCTYPE html>
at the first line?
private function generatePDF($transactions, $globalData){
$html = \View::make('pdfs.reminder')->render();
$pdf = \PDF::loadHTML($html);
return $pdf->stream();
}
pdfs.reminder.blade.php
<!DOCTYPE html>
<h1>Hello World</h1>
Upvotes: 0