Aha, thanks dude :-)

On Oct 19, 12:55 pm, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Fri, 2007-10-19 at 04:32 -0700, dbee wrote:
> > I'm creating a pdf document dynamically, I need to include barchart
> > data in the document. The  bar chart data is also created dynamically
> > with report lab. I can get the barchart data at my url ...
>
> > def barchart_interests(request):
>
> > .............
>
> >     #get a GIF (or PNG, JPG, or
> > whatever)
> >     binaryStuff = d.asString('gif')
>
> >     return HttpResponse(binaryStuff, 'image/gif')
>
> > Now I want to use that barchart in my pdf ...
>
> > def dyn_pdf(request):
>
> >    buffer = StringIO()
>
> >     # Create the PDF object, using the StringIO object as its
> > "file."
> >     p = canvas.Canvas(buffer)
>
> >     # Get the HttpResponseObject
> >     image = interests_barchart(request)
>
> >     # Insert the image into the pdf document
> >     p.drawInlineImage(image, 100,350, width=100,height=100)
>
> >     p.showPage()
> >     p.save()
>
> > Things that I've tried ....
>
> >        p.drawInlineImage(image._get_contents, 100,350,
> > width=100,height=100)
> >        Attribute Error: 'function' object has no attribute 'format'
>
> >        p.drawInlineImage(image.content, 100,350, width=100,height=100)
> >        I/O Error: Cannot open resource "GIF87a
>
> This one is close, but you're not reading the Reportlab documentation
> correctly. drawInlineImage() takes a filename or a PIL image object as
> its first argument, where as image.content is the binary data that is in
> the HttpResponse. So you need to create an Image object from that data
> first. This should be close:
>
>         from PIL import Image
>         from cStringIO import StringIO
>
>         ...
>         img = Image.open(StringIO(image.content))
>         p.drawInlineImage(img, ...)
>
> Read the PIL documentation for more possibilities.
>
> Regards,
> Malcolm


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to