How to convert an image with data uri

74 views
Skip to first unread message

Saikat Chakrabarti

unread,
Nov 25, 2009, 5:32:47 PM11/25/09
to Pisa XHTML2PDF Support
I have some html that I want to convert to a PDF. The HTML includes
some images with src pointing to a data uri, where the data uri is a
base64 encoded PNG image. The code is as follows:

def export(request):
dest = "test.pdf"
f = file(dest, "wb")
pdf = pisa.CreatePDF(cStringIO.StringIO("""<img src="data:image/
png;base64,iVBORw0KGgoAAAANSUhEUgAAAIEAAAAKCAYAAACT1z1LAAAAYklEQVRYhe3Yqw3AMBAEUTfhDva2/
yLCYuhSzB0SBUTBOXDzpOMGI/
9aQxm2D9tDUs9eC5LYHrZ3RExCKEpSj4hJCMV9hnCfE5spO4sImJW9O
+Fn3AuKIwDwRMTzWXS+A7gATOaWGR9elc8AAAAASUVORK5CYII=">"""),
f)
f.close()

if pdf.err:
dumpErrors(pdf)
else:
pisa.startViewer(dest)

The outputted PDF does not show any image (though I have tried using
pisa for other HTML, and it is working fine). The post here led me to
believe that data uris are supported by pisa -
http://groups.google.com/group/xhtml2pdf/browse_thread/thread/f0a0807acc3b90da/863ac82ffcfcad41?lnk=gst&q=data+uri#863ac82ffcfcad41
. What can I do to make this work? Or is this just not supported
yet?

Thanks!

Saikat
Reply all
Reply to author
Forward
0 new messages