4

this question on wkhtmltopdf has a specific component and a more general component to it.

generally: i am trying to extract a wide range of webpages into pdf files and i want wkhtmltopdf to work in as many cases as possible. its a pretty good tool but i often meet problems when it couldn't convert webpages. do you guys have a go-to set of flags that you use with wkhtmltopdf?

specifically: for example, a webpage that isn't anything far-out, but i am having problems with is http://gizmodo.com/microsoft-surface-book-review-so-good-i-might-switch-1737680767. when i run wkhtmltopdf without any flags (in Windows), i get the following:

>>wkhtmltopdf http://gizmodo.com/microsoft-surface-book-
review-so-good-i-might-switch-1737680767 blah.pdf
Loading pages (1/6)
Error: Failed loading page http://gizmodo.com/microsoft-surface-book-review-so-g
ood-i-might-switch-1737680767 (sometimes it will work just to ignore this error
with --load-error-handling ignore)
Warning: A finished ResourceObject received a loading progress signal. This migh
t be an indication of an iframe taking too long to load.
Warning: Received createRequest signal on a disposed ResourceObject's NetworkAcc
essManager. This might be an indication of an iframe taking too long to load.
Exit with code 1, due to unknown error.

if i follow the instructions and use the --load-error-handling ignore flag, the PDF file is generated, but its empty. how do i get wkhtmltopdf to work with this webpage?

i tried to look at other tools such as phantomJS with rasterize.js, but it has its own set of problems...

thanks guys!

2 Answers 2

9

This happens when Javascript is enabled and it is too slow to complete. If you need to run javascript to solve this problem add:

--javascript-delay 100000  

which adjust the wait time for Javascript to complete (it's in milliseconds). So in the example above it waits for 100 secs. Note if you run a multiple document conversion at once, this setting applies to the whole run, and not to each individual document. Therefore if, say, you convert some 100 input htmls in a single pdf output, you may need a longer delay.

I also add to my scripts:

--no-stop-slow-scripts

which enables: Do not Stop slow running javascripts.

5

Turns out its actually quite simple! simply use the "-n" flag! works like a charm!

3
  • 1
    Didn't work for me. I've just get the same message, with an without JavaScript enabled (ie. without or with -n). Plus disabling JavaScript might prevent some content from being shown, which is not good either.
    – philippe_b
    Commented Mar 22, 2016 at 9:21
  • 1
    @philippe_b - it worked for the latest version of wkhtmltopdf v0.12.3.2 (at least for me - on windows). but yeah, it disables some content in Javascript but this is as best as i can get till now
    – adrianX
    Commented Apr 13, 2016 at 8:21
  • Caution! This disables the javascript. If you want the javascript to work, go with @stason's solution. Commented May 14, 2020 at 1:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.