[reportlab-users] Drawing things alongside paragraphs

Donn donn.ingle at gmail.com
Fri Dec 19 09:19:42 EST 2008


On Friday, 19 December 2008 12:21:51 Robin Becker wrote:

> P = Paragraph('This is an Img <img

> src="http://www.reportlab.com/media/base/logo_bg.gif"/>',styleSheet['BodyTe

>xt'])

I tried to use the same URL and got nothing. Here is my stripped-down code (a
Django view) to show what I am trying. The text always appears, but never the
image.

\d

def desiderata_pdf(request,brotherpk=None):
styles = getSampleStyleSheet()
styleN = styles['Normal']
styleN.fontSize= 9
styleN.leading=11
styleH2 = styles['Heading3']
story = []
hcm = 0.5 * cm

# Create the HttpResponse object with the appropriate PDF headers.
response = HttpResponse(mimetype='application/pdf')
response['Content-Disposition'] = 'attachment; filename=TEST.PDF'
import os,sys
cwd=sys.path#os.getcwd() # getcwd shows "/"

# tried this, with many types of paths.
i='<img src="/var/www/media/incunabula/images/halo.gif" valign="top"/>'
# And this
i='<img src="http://www.reportlab.com/media/base/logo_bg.gif"/>'

story.append(Paragraph('<b>CWD is:</b>%s image?%s ' %(cwd, i), styleH2 ))

#create the basic page and frames
document = platypus.BaseDocTemplate(response,
leftMargin=hcm,rightMargin=hcm,topMargin=hcm,bottomMargin=hcm,pagesize=A5)

frameCount = 1
frameWidth = document.width/frameCount
frameHeight = document.height
frames = []

#construct a frame for each column
for frame in range(frameCount):
leftMargin = document.leftMargin + frame*frameWidth
column = platypus.Frame(leftMargin,hcm, frameWidth,
frameHeight,showBoundary=1)
frames.append(column)

template = platypus.PageTemplate(frames=frames)
document.addPageTemplates(template)
document.build( story )

return response



More information about the reportlab-users mailing list