I have managed to read SVG using rsvg and output it to PNG via Cairo, in Python.
Despite there being MANY similar questions, I've not seen any documentation on how to convert SVG into PDF through rsvg & cairo. I am aware of the command-line 'rsvg'/'rsvp-convert' tools, but want to incorporate the functionality into my Python code instead. No launching subprocess either.
For the sake of example, here's basically what I currently use to render PNG:
img = cairo.ImageSurface(cairo.FORMAT_ARGB32, w, h)
ctx = cairo.Context(img)
handler= rsvg.Handle(None, svgstr)
handler.render_cairo(ctx)
img.write_to_png(pngfilepath)
The question is: how would the code be changed to output PDF instead, so that vector format is kept; rasterization must not happen.