How to convert SVG images for use with Pisa / XHTML2PDF?

I use Pisa / XHTML2PDF to create PDF files on the fly in Django. Unfortunately, I also need to include SVG images, which I find difficult.

What is the best way: a) to convert SVG to PNG / JPG (in Python) or b) including SVG to export PDF from Pisa?

+3
source share
2 answers

There is a Java-Apache Batik SVG toolkit .

# Inkscape .

Python :

import rsvg
from gtk import gdk
h = rsvg.Handle('svg-file.svg')
pixbuf = h.get_pixbuf()
pixbuf.save('foobar.png', 'png')

from gtk import gdk, Lukasz, pixbuf, save, .

+2

" rsvg, , , : AttributeError: " gtk.gdk.Pixbuf " " save "- Nick Sergeant Apr 25 '09 at 0:10"

gdk pixbuf:

import rsvg
from gtk import gdk
h = rsvg.Handle('svg-file.svg')
pixbuf = h.get_pixbuf()
pixbuf.save('foobar.png', 'png')

, svg:

import rsvg
from gtk import gdk
h = rsvg.Handle()
h.write(svg_string)
h.close()
pixbuf = h.get_pixbuf()
pixbuf.save('foobar.png', 'png')
+1

Source: https://habr.com/ru/post/1707077/


All Articles