Beispiel #1
0
    def toArray(self, width=-1, height=-1, scale=1.):
        '''
        render to image buffer in RGBA format
        '''
        if CairoSVG is None:
            raise ImportError('cairo extension not available')

        svgfh = StringIO()
        self.write(svgfh)
        svgfh.seek(0)

        writer = CairoSVG(svgfh)
        return writer.toRGBA(width, height, scale)
Beispiel #2
0
    def writePDF(self, filename, width=-1, height=-1, scale=1.):
        '''
        render to pdf file
        '''
        if CairoSVG is None:
            raise ImportError('cairo extension not available')

        if isinstance(filename, basestring):
            fh = open(filename, 'wb')
        else:
            fh = filename

        svgfh = StringIO()
        self.write(svgfh)
        svgfh.seek(0)

        writer = CairoSVG(svgfh)
        writer.toPDF(fh, width, height, scale)