Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
683 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...