Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
717 views
in Technique[技术] by (71.8m points)

pdf generation - wkhtmltopdf failure when embed an SVG

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.

Or perhaps is there any other way to embed an SVG into an HTML file and then export it to PDF instead of wkhtmltopdf?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...