问题描述
我正在尝试在 Django 应用程序中使用 Python 从 SVG 输入文件生成 PDF.
I am trying to generate a PDF from a SVG input file with Python in a Django application.
我已经找到了 2 个可行的解决方案:cairo+rsvg 和 imagemagick,但它们都有一个问题:它们有一些我不想在服务器上安装的奇怪依赖项,例如 DBUS 和 GTK.
I have already found 2 working solutions: cairo+rsvg and imagemagick but they both have one problem: They have some strange dependencies that I do not want to install on a server, for example DBUS and GTK.
所以我要求另一种从 SVG 生成 PDF 的方法,而无需在服务器上安装所有这些愚蠢的依赖项.
So I am asking for another method for generating a PDF from SVG without having to install all these stupid dependencies on a server.
推荐答案
你考虑过 svglib?
它看起来很有前途,特别是因为 reportlab 是 特色Django 文档中的 pdf 工具.
It looks quite promising, especially as reportlab is the featured pdf tool in Django's docs.
from svglib.svglib import svg2rlg
from reportlab.graphics import renderPDF
drawing = svg2rlg("file.svg")
renderPDF.drawToFile(drawing, "file.pdf")
这篇关于从 SVG 输入生成 PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!