wkhtmltopdf failure when embed an SVG

前端 未结 4 529
-上瘾入骨i
-上瘾入骨i 2020-12-17 14:27

Has anyone in this vast space has ever had the luck to successfully create a PDF with an embedded SVG on an HTML? I\'ve been receiving segmentation fault all the time.

相关标签:
4条回答
  • 2020-12-17 14:52

    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;"

    0 讨论(0)
  • 2020-12-17 14:53

    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

    0 讨论(0)
  • 2020-12-17 15:01

    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.

    0 讨论(0)
  • 2020-12-17 15:01

    We fixed this problem by adding a width and height attribute to the svg besides the viewbox attribute.

    0 讨论(0)
提交回复
热议问题