如何转换 SVG 图像以用于 Pisa / XHTML2PDF?
我正在使用 Pisa/XHTML2PDF 在 Django 中动态生成 PDF。 不幸的是,我还需要包含 SVG 图像,我认为这不是一件容易的事。
a) 将 SVG 转换为 PNG / JPG(在 Python 中)或 b) 在从 Pisa 导出的 PDF 中包含 SVG 的最佳方法是什么?
I'm using Pisa/XHTML2PDF to generate PDFs on the fly in Django. Unfortunately, I need to include SVG images as well, which I don't believe is an easy task.
What's the best way to go about either a) converting the SVGs to PNG / JPG (in Python) or b) including SVGs in the PDF export from Pisa?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有基于 Java 的 Apache Batik SVG 工具包。
在 有关 C# 的类似问题中,建议使用 Inkscape 的命令行版本 用于此目的。
对于 Python,这里有一个来自 此讨论的有用建议线程:
Lukasz建议的步骤
from gtk import gdk
是必要的并且必须先于创建 pixbuf,否则您将无法获得save
方法,如 所观察到的原始海报。There's the Java based Apache Batik SVG toolkit.
In a similar question regarding C# it was proposed using the command line version of Inkscape for this.
For Python, here's a useful suggestion from this discussion thread:
the step
from gtk import gdk
, suggested by Lukasz, is necessary and has to precede creation of the pixbuf, otherwise you will not get thesave
method, as observed by the original poster.“我的 rsvg 可以工作,但是当我尝试保存时,我得到的是: AttributeError: 'gtk.gdk.Pixbuf' object has no attribute 'save' – Nick Sergeant 2009 年 4 月 25 日 0:10”
您需要导入 gdk访问 pixbuf 方法:
并从包含 svg 数据的字符串进行转换:
"I got rsvg working, but here's what I get when I try to save: AttributeError: 'gtk.gdk.Pixbuf' object has no attribute 'save' – Nick Sergeant Apr 25 '09 at 0:10"
You need to import gdk to have access to pixbuf methods:
And to convert from string that contains svg data: