Using Images in pdfs

809 Views Asked by At

Iam trying to render a pdf from a html ( with context). I am following the code given here. I am getting an image from another form in the basae 64 encoded format. Something like this

datauri = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=='

Now I am sending this datauri to the template using a context and in my template I am using this

<img src="{{ datauri}}">

to render the image. I use the context and html file as input to the render_to_pdf method mentioned in the link above. But I am getting the following error

'NoneType' object has no attribute 'bands'
Exception Location:     /usr/lib64/python2.6/site-packages/PIL/Image.py in split, line 1497

And the error location in views.py file is

    pdf = pisa.pisaDocument(StringIO.StringIO(html.encode("ISO-8859-1")), result)

Any idea on why this is happening and a way to overcome this? Thanks!

1

There are 1 best solutions below

0
On

try to use a different format than png , seems there is a bug with png images