@barryvdh -- firstly, thank you very much for writing this wrapper, much appreciated.
When I have a (blade) view pdfs.example like:
<!DOCTYPE html>
<html>
<head>
<title>Scantron Form</title>
{{ HTML::style('css/style.min.css') }}
</head>
<body>
<p>My code here</p>
</body>
and an associated route which maps to a controller function that contains:
$pdf = PDF::loadView('pdfs.example');
return $pdf->stream();
I get 'failed to load pdf document' when I try to view the pdf in-browser. I am using a laravel homestead environment and accessing it with a url like http://mysite.dev:8000/pdf/example.
I've found that if I replace the HTML::style() line with <style type="text/css"> and paste in my minified css file, everything works as expected.
laravel.log shows [2015-01-05 12:03:24] local.ERROR: exception 'RuntimeException' with message 'The exit status code '1' says something went wrong:
Let me know if there's anything else I can provide to help explain the issue. I'm not sure whether this is an error with snappy itself or the wrapper, or if I'm just doing something wrong?
Thanks for any insight you can provide.
Update: I linked to this issue in my related thread over on laracasts
So you are using Nginx right, not the built-in server?
Correct, using nginx from the vm, not the php built-in server. For now I've done the workaround of grabbing the contents of that file and putting them into style tags. Not ideal but it seems to work. I could make an example app later on and reproduce the issue if that would help?
Needs to be an absolute path and not a relative path for CSS and javascript includes. I ran into this last night.
So the css and javascript paths need to be "http://mysite.dev:8000/css/app.css". For whatever reason wkhtmltopdf executable doesn't seem to resolve those assets as being relative to the page. After I changed my pdf template to use absolute urls, the problem resolved it self for me.
I'm not sure if that issue is still relevant, but I ran into a similar one with Laravel's url helper.
After a bit of debugging I've realised that the urls included in my HTML were not the same whether I was generating the PDF file from the site itself or a queue (CLI)
http://localhost doesn't return anything in my environment hence the issue.
In order to get it working correctly, I just had to modify the url settings in my app's config/app.php. That simple...
Btw, thanks for your wonderful work Barry!
Homestead solution for me.
sudo nano /etc/hosts
laravel.local127.0.0.1 laravel.local
asset function <link href="{{ asset('css/app.css') }}" rel="stylesheet">
I'm using Laravel 5.7 with Homestead on Windows 10
So I had a proyect on Laravel 4.2 where I was able to include the CSS files like this
<link rel="stylesheet" href="{{public_path().'/css/all.css'}}">
Now on this new proyect using the same logic is giving me an error, so I use @dereckmartin solution and it worked for my. So I include the CSS files like this
<link rel="stylesheet" href="http://test.localhost:8000/public/css/all.css">
but I want to know why I can't use the public path anymore, I don't like to leave it like this because we are several people on the proyect so they need to change the url everytime they want to see a pdf
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Any issues with PDF rendering itself that are not directly related to this package, should be reported on https://github.com/KnpLabs/snappy instead. When having doubts, please try to reproduce the issue with just snappy.
If you believe this is an actual issue with the latest version of laravel-snappy, please reply to this issue so we can investigate further.
Thank you for your contribution! Apologies for any delayed response on our side.
Most helpful comment
I'm not sure if that issue is still relevant, but I ran into a similar one with Laravel's url helper.
After a bit of debugging I've realised that the urls included in my HTML were not the same whether I was generating the PDF file from the site itself or a queue (CLI)
http://localhost doesn't return anything in my environment hence the issue.
In order to get it working correctly, I just had to modify the url settings in my app's config/app.php. That simple...
Btw, thanks for your wonderful work Barry!