I have a Laravel 5.3 application (that uses URL rewriting) that runs on nginx 1.12.1 on an Ubuntu server.
I want to create PDF report, and I find this mPDF wrapper for Laravel. My page works from the browser but throw 404 error when mPDF tries to generate PDF. After investigation, I found that it fails on this line in the html:
<link href="/css/app.css" rel="stylesheet">
I dug into mPDF source and found out it would fail in a line like:
$content = @file_get_content("https://mywebaddr/css/app.css");
So first thing, instead of returning false everythings stops and nginx displays Error 404 (despite the fact that the url is valid, I can open my css in my browser, and despite the ignore error operator) but that is not the main problem.
And second thing why does this request fails? I checked and allow_url_fopen is ON, the request could fail with 401 Unauthorize if it was a credential issue.
I don't understand this behaviour, may someone lead me to the solution?
EDIT: My routes: (the first displays the report as a webpage and the second displays a PDF).
| | GET|HEAD | report/{id} | | App\Http\Controllers\ReportController@viewReport | web |
| | GET|HEAD | report/{id}/download | | App\Http\Controllers\ReportController@downloadReport | web |
Note that when I remove the css include I succeed in getting my PDF, except that my images are broken. Note also that this isn't CSS that generate the 404 but mPDF PHP class that tries to file_get_content it.
Code for PDF is:
$pdf = PDF::loadView('report.index', $datas);
return $pdf->stream('document.pdf');