wkhtmltopdf failure when embed an SVG

谁说我不能喝 提交于 2019-11-29 05:47:13
Yuriy Chemerys

I had similar problem. Seems like javascript embedded in SVG image can cause segmentation fault.

I was generating SVG graphs using pygal Python module. To successfully generate PDF from HTML with SVG graphs I had to do several things:

  1. Remove reference to javascript. (In case of pygal add js=() key to a graph constructor).
  2. Specify image size in svg tag, like

    <svg ... width="300" height="200">
    

    (In case of pygal use explicit_size keywoard)

  3. Embed SVG image into img tag in base64 encoded form, like

    <img src="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0...">
    

I was using 11th version of wkhtmltopdf.

If this fix doesn't work for others, here's what worked for me with chartist.js, and wkhtmltopdf 0.12.2.1 under Ubuntu 64. (Credit to Panokev)

Add this to your javascript before all other JS.

{

Function.prototype.bind = Function.prototype.bind || function (thisp) {
    var fn = this;
    return function () {
        return fn.apply(thisp, arguments);
    };
};

Definitively set width style for chart div, for example - style="width:950px;"

Right .. I managed to pull it off finally ... all needed was a bit of treatment on the original eps file. I opened the file with illustrator and chose to "flatten transparency" .. maybe what it does was to flatten the many layers of the file or something .. then save as svg .. and it rendered nicely in the PDF ..

Hopefully this helps if anyone out there would have the same issue as I did. Thank you! :D

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