[cairo] Can I use pycairo to convert svg file to pdf ?

Sebastian Koppehel basti at bastisoft.de
Tue Mar 20 03:42:58 PDT 2007


Am Dienstag, den 20.03.2007, 09:56 +0100 schrieb KLEIN Stéphane:

> My question : can I make a python script (with pycairo) to open svg
> file and convert it to pdf ?

Yes.

Primitive outline:

        import cairo, rsvg
        from sys import argv
        
        WIDTH, HEIGHT = 100, 100
        
        surf = cairo.PDFSurface(argv[2], WIDTH, HEIGHT)
        cr = cairo.Context(surf)
        rsvg.Handle(argv[1]).render_cairo(cr)
        cr.show_page()

Regards,

 - Sebastian



More information about the cairo mailing list