嵌入SVG时wkhtmltopdf失败 [英] wkhtmltopdf failure when embed an SVG
问题描述
在如此广阔的空间中,有没有人能成功创建在HTML上带有嵌入式SVG的PDF?我一直都在遇到细分错误.
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.
也许还有其他方法可以将SVG嵌入HTML文件,然后将其导出为PDF,而不是wkhtmltopdf
?
Or perhaps is there any other way to embed an SVG into an HTML file and then export it to PDF instead of wkhtmltopdf
?
推荐答案
我遇到了类似的问题.似乎将javascript嵌入SVG图像中可能会导致分割错误.
I had similar problem. Seems like javascript embedded in SVG image can cause segmentation fault.
我正在使用 pygal Python模块生成SVG图.为了成功地使用SVG图形从HTML生成PDF,我必须做几件事:
I was generating SVG graphs using pygal Python module. To successfully generate PDF from HTML with SVG graphs I had to do several things:
- 删除对javascript的引用. (如果是 pygal ,请将js =()键添加到图形构造函数中.)
-
在svg标签中指定图像大小,例如
- Remove reference to javascript. (In case of pygal add js=() key to a graph constructor).
Specify image size in svg tag, like
<svg ... width="300" height="200">
(如果是pygal,请使用 explicit_size 键区)
(In case of pygal use explicit_size keywoard)
将SVG图像以base64编码形式嵌入 img 标签,例如
Embed SVG image into img tag in base64 encoded form, like
<img src="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0...">
我正在使用wkhtmltopdf的第11版.
I was using 11th version of wkhtmltopdf.
这篇关于嵌入SVG时wkhtmltopdf失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!