vendredi 9 février 2018

Unable to download PDF created by barryvdh/laravel-snappy

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:

  • The complexity of the PDF HTML doesn't have any bearing. I can try outputting a simple <h1>Hello World</h1> and I get the same result (nothing) that I would from outputting my multi-page HTML
  • If I look at the HTML being generated it all looks fine
  • If I try to save() the PDF it is generated correctly and I can view it without issue
  • I've tried using both PDF::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.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire