I am trying to generate a PDF from a SVG input file with Python in a Django application.
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.
So I am asking for another method for generating a PDF from SVG without having to install all these dependencies on a server.
Advertisement
Answer
Have you considered svglib?
It looks quite promising, especially as reportlab is the featured pdf tool in Django’s docs.
JavaScript
x
6
1
from svglib.svglib import svg2rlg
2
from reportlab.graphics import renderPDF
3
4
drawing = svg2rlg("file.svg")
5
renderPDF.drawToFile(drawing, "file.pdf")
6