469,568 Members | 1,598 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,568 developers. It's quick & easy.

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
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 ?
Jun 27 '08 #1
1 4692
dbee wrote:
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 ...
.......

I think you should ask this on the reportlab users list which you can
find at http://two.pairlist.net/pipermail/reportlab-users/

As for your specific problem perhaps you should start with some simple
examples.
--
Robin Becker
Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Jacky11 | last post: by
reply views Thread by BATISTA | last post: by
reply views Thread by Chris | last post: by
11 posts views Thread by Ryan | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.