Report Lab Image Flowable Issue ..

D

dbee

I'm try to generate a report that will span multiple pages and have
dynamic content using python reportlab. I have no issues with regards
to generating images and then using p.drawInlineImage(signup_img,
100,150) to draw them onto the canvas.

The problem that i have comes when i try to create flowables so that
my layout can span multiple pages. The images themselves never
actually show up on the page ...

# Import pdf
generator
from cStringIO import StringIO
from reportlab.pdfgen import canvas
from reportlab.pdfgen.canvas import Canvas
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.lib.units import inch
from reportlab.platypus import Paragraph, Frame
from PIL import Image

# Create the HttpResponse object with the appropriate PDF
headers.
response = HttpResponse(mimetype='application/pdf')
response['Content-Disposition'] = 'attachment;
filename=somefilename.pdf'

buffer = StringIO()

styles = getSampleStyleSheet()
styleN = styles['Normal']
styleH = styles['Heading1']
story = []

#add some
flowables
story.append(Paragraph("This is a Heading",styleH))
story.append(Paragraph("""This is a paragraph in <img src='http://
images.google.com/intl/en_ALL/images/images_hp.gif' width='200'
height='200' /> style"\
"",styleN))

c = Canvas(buffer)
f = Frame(inch, inch, 6*inch, 9*inch, showBoundary=1)
f.addFromList(story,c)
c.save()

# Get the value of the StringIO buffer and write it to the
response.
pdf = buffer.getvalue()
buffer.close()
response.write(pdf)

This should generate a pdf with the google image in it no ? The pdf
gets generated but no image comes out.

When I try the other option of using image flowables, I get only an
error. The reportlab docs example shows an Image flowable being called
like ... Image("lj8100.jpg") .... but when i try to call the object
directly i get an error which suggests that i should use Image.new or
Image.open to call the object ...

# Create image from /tmp
im = Image("/tmp/car_dealership.jpg", width=2*inch, height=2*inch)
im.hAlign = 'CENTER'

#add some
flowables
story.append(Paragraph("This is a Heading",styleH))
story.append(Image(im))

TypeError: 'module' object is not callable for the im = Image( ....)

When i try to feed the image manually ...

interest_image = interests_barchart(request)
im = Image.open(StringIO(interest_image.content))

#add some
flowables
story.append(Paragraph("This is a Heading",styleH))
story.append(im)

I get ... AttributeError: getSpaceBefore ... which seems to suggest
that im isn't a flowable ...

Can anyone help pls ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top