Javascript Execution issue
nazarhussain opened this issue · 7 comments
Hi,
I have to create pdf for a page which has graphs as well. I am using Google charts for drawing the graphs. I have to do this from background rake task, so I generated the html first and then using Wisepdf::Writer.new.to_pdf
to generate the pdf.
If I open up the generated html file in browser it displays the graphs accurately. but in pdf it do not display any graph.
I tried to investigate the issue, but can't solve it. Is this a bug or limitation in to_pdf
method?
One thing I noticed is, I wrote the html into an html file and then used command line wkhtmltopdf
to convert it and it shows the graphs very well.
So there is an issue within wisepdf wrapper for dealing js.
Hello. Thanks for this issue, in fact I have the same issue now.
What version of wkhtmltopdf are you using? 0.10 and newer has --javascript-delay option that allows to run JS. Also please note that wkhtmltopdf cannot perform any AJAX calls.
Can you show me code, that you perform in your view?
I also figured out the same issue. Initially i was using 11.0.rc1
version that was causing the problem, and now I switched to 0.9.9
. It solves my issue a bit.
But still there is a problem. When I open up the html file in browser it shows all graphs very well. but when I generate the pdf, some graphs are missing and also the behavior is not consistent. Sometimes it misses 2 graphs and sometimes 3.
Here is the html file that I am using https://www.dropbox.com/s/xk5z04mvzo811sn/Report.html
Look, wkhtmltopdf older then 0.10 does not have any option to do wait while javascript works.
Here is what you got: you load your page to wkhtmltopdf, it tries to create pdf, but your graphs are not fully rendered yet - they simply didn't have enough time to render.
As I said, I have the same problem now and I am trying to find solution for it. If you will find anything – please let me know.
Thanks.
Ok. I am also trying to get things done in any way, because have to meet a deadline. If you find the solution please let me know ASAP. I will also try to catch those things with new wkhtmltopdf.
By the way wkhtmltopdf older then 0.10 have option --redirect-delay
and it was replaced by --javascript-delay
in wkhtmltopdf 0.10 You should try use these options. With highcharts it works pretty well for me.
If you use some options marked red * from list (http://madalgo.au.dk/~jakobt/wkhtmltoxdoc/wkhtmltopdf-0.9.9-doc.html) be careful because these options are only available using patched QT. Otherwise you will be have Broken Pipe Error
Thanks man! The new static binary for 11.0.rc1
with --javascript-delay
was creating the error Segmentation fault (core dumped)
for me.
Switching back to 9.9
and using --redirect-delay
solves the issue. And now all the graphs are generating accurately.
Thanks for your help.