Report Lab Image Flowable Issue ..



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
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
response = HttpResponse(mimetype='application/pdf')
response['Content-Disposition'] = 'attachment;

buffer = StringIO()

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

#add some
story.append(Paragraph("This is a Heading",styleH))
story.append(Paragraph("""This is a paragraph in <img src='http://' width='200'
height='200' /> style"\

c = Canvas(buffer)
f = Frame(inch, inch, 6*inch, 9*inch, showBoundary=1)

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

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 or 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
story.append(Paragraph("This is a Heading",styleH))

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

When i try to feed the image manually ...

interest_image = interests_barchart(request)
im =

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

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