Create pdf with wkhtmltopdf and rendering javascript

浪子不回头ぞ 提交于 2019-11-30 19:36:01
Rick van Hal

In our project we do something simular, with success. We use wkhtmltopdf 0.9.9 in combination with Highcharts at the moment. With jQuery flot we had success too after a little tweaking. In our project we first render the view to a string and pass it to wkhtml using it's stdin. Then we catch the stdout of wkhtml and pass it back to the browser.

Your wkhtml-setting seems to be right, except we use stdin and stdout. Don't know if that can be a problem.

If you use one of those charts I think I can help you. What chart are you using?

One last note: Wkhtmltopdf 0.10rc2 seems to have some problems loading external resources (js/css) from localhost when using a portnumber different from port 80.

It looks like you're trying to get the output of a chart, which judging by the tags is from an Extjs 4 script.

The ext script is probably using some of the chart's animation, and will certainly be waiting for javascript events to execute and render the chart. It's probably therefore not done by the time the default time (200 ms) is done.

A quick fix would be to add the javascript-delay page option to the command line:

wkhtmltopdf http://dev.sencha.com/deploy/ext-4.0.2a/examples/charts/Mixed.html --javascript-delay=2000 test.pdf will certainly work on *nix, and a similar thing should work on windows.

I was using wkhtmltopdf 0.9.9 and the pdfkit ruby gem, and having a similar problem.

I fixed it by changing all tags to use absolute urls. It seems that wkhtmltopdf didn't know what url the page was accessed via so relative resources weren't being loaded. I don't know if that's a limitation of the pdfkit or wkhtmltopdf.

I got the idea from https://github.com/mileszs/wicked_pdf.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!