Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combination of --window-status and --javascript_delay in wkhtmltopdf

Tags:

wkhtmltopdf

I want to use wkhtmltopdf to render both pages I control (in which case I can set the window.status when done rendering) and (occasionally) pages I don't control. According to this thread on the mailing list I should be able to set --window-status to some value, and --javascript-delay as well, and rendering starts as soon as either of these conditions is met. That's not my experience; the command wkhtmltopdf --javascript-delay 10000 --window-status imdone http://www.google.com/ /tmp/google.pdf waits forever (version 0.12.3, both on OSX and linux). How can I get the behaviour as described on the mailinglist?

like image 488
Claude Avatar asked Jun 28 '16 16:06

Claude


1 Answers

One workaround is to use the --run-script tag to set the window.status after some time manually -- this works both on the version that uses the patched and that that uses the unpatched QT. Note however that --run-script seems to have a small bug in escaping its parameter. Therefore the following line will give you the behaviour requested:

wkhtmltopdf --window-status imdone --run-script \
'window.setTimeout(function(){window.status="imdone";},1000);' \
http://google.com/ /tmp/google.pdf

Note that because of aforementioned bug, it doesn't work if one puts spaces in the --run-script argument, hence the following will not work

wkhtmltopdf --window-status imdone --run-script \
'window.setTimeout(function (){window.status = "imdone";}, 1000);' \
http://google.com/ /tmp/google.pdf
like image 74
Claude Avatar answered Sep 24 '22 07:09

Claude