Skip to content
Advertisement

Generating PDFs from SVG input

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.

from svglib.svglib import svg2rlg
from reportlab.graphics import renderPDF

drawing = svg2rlg("file.svg")
renderPDF.drawToFile(drawing, "file.pdf")
Advertisement