Closed joruzani closed 10 years ago
those tmp files are created... which are the incomplete html and pdf (all the elements just with some css missing) and remain in the directory
Is this with all views? Can you try with a simple view with just plain text? When you output the html of the view directly, does it all work?
Thanks for your response.
I haven't tried with any other view (will do), and the one I'm trying is really simple, just a list of items so just a table with text (it had images but I removed all for the moment).
The view loads well as if I dd($pdf) the object is created and the view displayed correctly(the ["html"] => string()).
I changed the timeout in the snappy AbstractGenerator.php so it may have more time to finish, I try with 360 and got the same result... I just set it to 0 (so timeout is disabled) and will let it run for a while to see what happens.
Edit: With no timeout is the browser the one that throws connection has timed out =(
Edit 2: without images it throws (in just 1 sec):
RuntimeException
The exit status code '1' says something went wrong: stderr: "Loading pages (1/6) [> ] 0% [======> ] 10% [=======> ] 12% [============================================================] 100% Counting pages (2/6) [============================================================] Object 1 of 1 Resolving links (4/6) [============================================================] Object 1 of 1 Loading headers and footers (5/6) Printing pages (6/6) [> ] Preparing [============================================================] Page 1 of 1 Done Exit with code 1 due to http error: 1302 " stdout: "" command:/vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64 '/tmp/knp_snappy539b125e497e95.90154509.html' '/tmp/knp_snappy539b125e4990c3.19775282.pdf'.
this is a snappy error so will check it and see what I find.
I've made various test, turns out the problem is (as expected) in the snappy and/or wkhtmltopdf... so I don't know if a should keep posting here.
Anyway here is what I found:
this will work: $snappy->generate('http://www.google.com', '/tmp/testPdf.pdf');
this will work pretty well but maybe not perfectly $snappy->generate('http://www.w3schools.com', '/tmp/testPdf.pdf');
throws (still generating the file):
RuntimeException
The exit status code '1' says something went wrong: stderr: "Loading pages (1/6) [> ] 0% [======> ] 10% QSslSocket: cannot resolve SSLv2_client_method QSslSocket: cannot resolve SSLv2_server_method [========> ] 14% [=========> ] 16% [===========> ] 19% [============> ] 21% [==============> ] 24% [===================> ] 33% [=========================> ] 43% [================================> ] 54% [========================================> ] 68% [============================================================] 100% [======> ] 10% [============================================================] 100% [======> ] 10% [============================================================] 100% [======> ] 10% [======> ] 10% [==================> ] 30% [==============================> ] 50% [==========================================> ] 70% [============================================================] 100% Counting pages (2/6) [============================================================] Object 1 of 1 Resolving links (4/6) [============================================================] Object 1 of 1 Loading headers and footers (5/6) Printing pages (6/6) [> ] Preparing [==============================> ] Page 1 of 2 [============================================================] Page 2 of 2 Done Exit with code 1 due to http error: 1005 " stdout: "" command: /vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64 'http://www.w3schools.com' '/tmp/testPdf.pdf'.
and locally as in: $snappy->generate('http://localhost:8000/items/9', '/tmp/testPdf.pdf');
throws (still generating the file):
ProcessTimedOutException
The process "/vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64 'http://localhost:8000/subastas/9' '/tmp/testPdf.pdf'" exceeded the timeout of 120 seconds.
I'll keep trying as I need this, but as the problem is not with your wrapper I won't post anymore unless you have no problem with that. If I found a solution I'll definitely post it =)
Ok, the solution is really simple actually, the problem is that it wont work on dev(local) environment because for some reason the wkhtmltopdf doesn't like localhost:8000... whatever. (I guess it has to be with how wk handless the address... maybe?)
and for example for the css the href needs to be complete (with http://):
this works -> http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css this wont -> netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css
same with images or any other reference you may have.
That was all, sorry for any inconvenience =)
I got the same error.
Symfony \ Component \ Process \ Exception \ ProcessTimedOutException The process "/media/d_drive/vagrant/trusty64/www/travel/vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64 --lowquality '/tmp/knp_snappy53ff3daf740c62.72948544.html' '/tmp/knp_snappy53ff3daf741394.68202889.pdf'" exceeded the timeout of 60 seconds.
whenever I try to call a css file in header, I will get the error.
{{ HTML::style('css/bootstrap.min.css') }}
or
<link rel="stylesheet" href="http://localhost:8000/css/bootstrap.min.css">
I will not get the error if I remove it or replace it with full url path
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
So the problem is I can not use my own css and put it into my template.
I ran on local by using built-in php server on ubuntu 14.04 (64 bit)
php artisan serve
anyway both file was create in tmp
/tmp/knp_snappy53ff3daf740c62.72948544.html
/tmp/knp_snappy53ff3daf741394.68202889.pdf -> I opened this file and it looked fine.
anyone got any solution for this?
Thank you
Okay now facing the same issue after updating something (not sure what). The commands executes fine and the file is generated, but somehow not received correctly.
I also encountered this issue, but in my case the timeout was due to a HostNotFoundError. Just remember if you add input rules to iptables and its policy is "drop", and you limit to a select few IP addresses, make sure you allow localhost access to itself. This is what caused the issue for me - also the process doesn't terminate, but that's a whole other issue.
Edit: I forgot to mention that this is marginally related to the inability to add relative urls.
I just stumbled upon the same problem when adding an image from my own host which indeed is localhost:8000
:
Any solution - workaround for this? Is it a wkhtmltopdf
issue? Port problem?
Try localhost with default HTTP port (80). Be sure that this image is available from machine where wkhtmltopdf tool is installed. Try download this image using wget.
Thanks @colejarczyk . I couldn't switch the port to 80 due to permissions on my machine. But I switched to 8080.
A wget
wget http://localhost:8080/logo.jpg
would just work fine.
But I still have the same problem.
The strange thing is the wget http://localhost:8000/logo.jpg
would take some time but work too.
Try to execute render command in console. To get command you can "echo" it by call "getCommand" method of AbstractGenerator class. You should get more verbose output about problems.
Good tip, thanks @colejarczyk . :+1: I will be able to check the project again next year. I will report then!
Still checking the port problem. Testing the command next @colejarczyk .
Feel free to follow my steps on my gist: https://gist.github.com/webdevilopers/e0d34a1c04ef2050a450
I tried to get the command:
$html = $this->renderView('AppBundle:Bundle:list.html.twig', $viewParameters);
$snappy = $this->get('knp_snappy.pdf');
echo $snappy->getInternalGenerator()->getCommand($html, 'test.pdf', array(
'orientation' => 'Landscape',
'images' => true,
'enable-javascript' => true
));
The result is a simple
wkhtmltopdf --lowquality --orientation 'Landscape' --images --enable-javascript '
I think the command is incomplete since it uses a symfony2 twig rendered template as $input
, @colejarczyk?
I found the root of my problems caused by the PHP built-in server because it is single-threaded, @colejarczyk .
Fur further details: https://gist.github.com/webdevilopers/e0d34a1c04ef2050a450#comment-1368355
Thanks anyway!
I would never thought that you'll trying to test wkhtmltopdf in PHP built-in server :) To get full command, edit Abstract Generator class and echo command from method execute. Use Vagrant as environment for testing.
Believe me @colejarczyk , it was not my choice! ;) And yes, Vagrant is next! :)
I meet the same timeout problem in our production server. It is weird that most of time, everything works fine and we can generate the PDF. I am using {{ HTML::style('my.css') }} or {{ HTML::script('my.js') }} for all css and js file. Does anyone know how to fix this problem?
I have the same problem and was only realized it was due to the unstable version of wkhtmltopdf (0.11rc1). Wkhtmltopdf was hang and not returned, eventually causing the timeout. Switching to 0.12.1 fixed the problem.
I have the same problem but in my case temp html files aren't being created and It works fine for few views but for one view its giving me problem The view causing problem is reading data from a rest api and contains few images. when I print the view content it's proper but when I try to create PDF its giving me timeout error. Please help me. Thanks in advance!
I also run the PHP built in server and get a timeout-error if i try to access external css/js files. If i inline everything then it works like a charm.
Did you check my comment @fatihict ? https://github.com/barryvdh/laravel-snappy/issues/9#issuecomment-69172040
@webdevilopers Yes, i saw you comment. Thanks for your help.
We also have the timeout, but it is expected because the html result is huge so it does really take Snappy over 60 seconds to generate the PDF. All issues I've found are related to wkhtmltopdf
is waiting for content, but none of them actually provide a solution to increase the timeout for the Process
component.
Is there another option next to calling set_time_limit()
before the PDF will be generated? Can't seem to get the actual Process
itself, otherwise setting the limit would be easy.
Edit: actually found the answer for that, the AbstractGenerator
has a editable timeout parameter for that:
$this->get('knp_snappy.pdf')->getInternalGenerator()->setTimeout(300);
Thanks @rvanlaak.
@rvanlaak if i set this in the AppServiceProvider will all calls to Snappy pdf now have this timeout?
@bgarrison25 you've got a link to the class you mean? We don't use this laravel wrapper bridge but use the KnpSnappyBundle, but I can't find the file in that bundle or even in this bundle or snappy
itself.
@barryvdh Maybe my issue #129 has the same solution as @rvanlaak https://github.com/barryvdh/laravel-snappy/issues/9#issuecomment-193173498 mentioned.
On our dedicated the timeout issue was solved by disabling ipv6.
I had similar issue.
I solved it by calling {{public_path('css/mycss.css')}}
instead of URL::to()
or asset()
Specifying a timeout value in config/snappy.php
stopped this error occurring in my project.
I had similar issue. I solved it by calling
{{public_path('css/mycss.css')}}
instead ofURL::to()
orasset()
It worked for me ! Anyone can explain this?
I had similar issue. I solved it by calling
{{public_path('css/mycss.css')}}
instead ofURL::to()
orasset()
It worked for me ! Anyone can explain this?
The wkhtmltopdf does not use the actual browser domain to resolve the files. The wkhtmltopdf binary is on your machine and needs the real file path to the associated files like images and stylesheets.
With public_path()
you get the full path string like /var/www/html/public/css/mycss.css
instead of http://example.org/css/mycss.css
.
I had the same issue before.
If someone else has this problem, well I found this kind-of solution .. i also use ngrok to put my site on the internet
Delete every redirects you have in hosts file (in linux its etc/hosts) except for example
mysite.test 127.0.0.1
also edit httpd-vhosts.conf file and delete other vhosts you have.. then run command from terminal ./ngrok http mysite.test:80
It should work.
I tried to use php -s command but it didn't work.
I use lampp (xampp for linux)
I had similar issue. I solved it by calling
{{public_path('css/mycss.css')}}
instead ofURL::to()
orasset()
Thanks!!!!, This has worked for me.
I have this issue too. Mine is because of image in pdf which was taken form asset. I remove the image it works.
I had the same issue, it was because of internet (slow or not working), I then switched to different network and works fine. Just in case anyone have the same problem :-)
Hi, I'm having a hard time making this work and don't know what to check.
Symfony \ Component \ Process \ Exception \ ProcessTimedOutException The process "/vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf --lowquality '/tmp/knp_snappy539a1b5171a923.27143750.html' '/tmp/knp_snappy539a1b5171b010.24930374.pdf'" exceeded the timeout of 60 seconds.
Thats been thrown.
Any ideas? I already check that the bin is working
Thanks for any help =)