469,609 Members | 1,657 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

ReportLab - Frames - Images

I have been trying all day to get this to work. My complete code is
below. I can get my text into the PDF, I can get my image in the PDF.
What I can't get to work is frames so that the image (logo) appears to
the right of the text. The image always appears first and then the text
below on the next line.

Please help.
Chuck

*************** CUT ***********************
from reportlab.pdfgen import *

from reportlab.platypus import *

from reportlab.lib.units import inch
from reportlab.platypus import SimpleDocTemplate
from reportlab.platypus import flowables
from reportlab.lib.enums import TA_LEFT, TA_RIGHT, TA_CENTER,
TA_JUSTIFY

from reportlab.lib.pagesizes import letter

#precalculate some basics
top_margin = letter[1] - inch
bottom_margin = inch
left_margin = inch
right_margin = letter[0] - inch
frame_width = right_margin - left_margin

def bill(canvas, doc):
canvas.saveState()
canvas.restoreState()

def run():
doc = []
from reportlab.lib.styles import ParagraphStyle
from reportlab.platypus import Image

pdf = SimpleDocTemplate('bill2.pdf', pagesize = letter)

#need a style
normal = ParagraphStyle('normal')

doc.append(Image("pic.jpg", 100, 71)) #Logo

para = Paragraph("Some text1", normal)
doc.append(para)
para = Paragraph("Some text2", normal)
doc.append(para)
para = Paragraph("Some text3", normal)
doc.append(para)
para = Paragraph("Some text4", normal)
doc.append(para)
para = Paragraph(" ", normal)
doc.append(para)
doc.append(HRFlowable(color="black", thickness=3, width="100%"))
pdf.build(doc,bill)

run()
*************************** CUT ***********************************

Jan 15 '07 #1
2 6665
Chuck wrote:
I have been trying all day to get this to work. My complete code is
below. I can get my text into the PDF, I can get my image in the PDF.
What I can't get to work is frames so that the image (logo) appears to
the right of the text. The image always appears first and then the text
below on the next line.

Please help.

you'll get more help at the reportlab users list (see

http://two.pairlist.net/pipermail/reportlab-users/ )

Anyhow I got some output from your script, by making two changes

*************** CUT ***********************
from reportlab.pdfgen import *
...........
>
pdf = SimpleDocTemplate('bill2.pdf', pagesize = letter)

#need a style
normal = ParagraphStyle('normal')

doc.append(Image("pic.jpg", 100, 71)) #Logo

para = Paragraph("Some text1", normal)
doc.append(para)
para = Paragraph("Some text2", normal)
doc.append(para)
para = Paragraph("Some text3", normal)
doc.append(para)
para = Paragraph("Some text4", normal)
doc.append(para)
para = Paragraph(" ", normal)
doc.append(para)
doc.append(HRFlowable(color="black", thickness=3, width="100%"))
change(1)
doc.append(flowables.HRFlowable(color="black", thickness=3, width="100%"))
>

pdf.build(doc,bill)
change(2)

pdf.build(doc)
>
run()
*************************** CUT ***********************************

I also had to change the name of the image to one on my system.

Hope this helps
--
Robin Becker
Jan 15 '07 #2
Thanks for the help. I made you changes but it still puts the picture
above the text, not beside the text.

I also found a user group at
http://news.gmane.org/gmane.comp.python.reportlab.user . It may be the
same. I have now posted there.

Chuck

Jan 16 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Robin Becker | last post: by
4 posts views Thread by Active8 | last post: by
1 post views Thread by Com Dot | last post: by
25 posts views Thread by Steal | last post: by
27 posts views Thread by Murray R. Van Luyn | last post: by
reply views Thread by norseman | last post: by
16 posts views Thread by Laszlo Nagy | last post: by
reply views Thread by Robin Becker | last post: by
reply views Thread by Solution2021 | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.