Embed .SVG files into PDF using reportlab

As mentioned by skidzo, you can totally do this with the svglib package, which you can find here: https://pypi.python.org/pypi/svglib/

According to the website, Svglib is a pure-Python library for reading SVG files and converting them (to a reasonable degree) to other formats using the ReportLab Open Source toolkit.

You can use pip to install svglib.

Here is a complete example script:

# svg_demo.py

from reportlab.graphics import renderPDF, renderPM
from reportlab.platypus import SimpleDocTemplate
from svglib.svglib import svg2rlg


def svg_demo(image_path, output_path):
    drawing = svg2rlg(image_path)
    renderPDF.drawToFile(drawing, output_path)

if __name__ == '__main__':
    svg_demo('/path/to/image.svg', 'svg_demo.pdf')

Yesterday I succeeded in using svglib to add a SVG Image as a reportlab Flowable.

so this drawing is an instance of reportlab Drawing, see here:

from reportlab.graphics.shapes import Drawing

a reportlab Drawing inherits Flowable:

from reportlab.platypus import Flowable

Here is a minimal example that also shows how you can scale it correctly (you must only specify path and factor):

from svglib.svglib import svg2rlg
drawing = svg2rlg(path)
sx = sy = factor
drawing.width, drawing.height = drawing.minWidth() * sx, drawing.height * sy
drawing.scale(sx, sy)
#if you want to see the box around the image
drawing._showBoundary = True