[reportlab-users] Multiple Columns overflowing into each other?

Erik Wickstrom erik at erikwickstrom.com
Wed Oct 24 15:54:56 EDT 2007


Hi,

I'm try to lay out my PDF so that there will be a skinny column of
text down the left side (about an inch or 2 thick), and another
region of the page which has the main article. I want the article to
wrap around an image (with caption) on the right side of the page.
Basically it will look like a newspaper layout when I'm finished.

I'm running into some problems thought. After reading the platypus
chapter in the docs, I thought I'd need to create a Frame for each
column, and then use flowables inside the Frames.

Problem is that the first flowable (left column) is overflowing the
left frame and into the main "article" Frame. If I shorten the
content of the first flowable, then the article "up-flows" into the
left frame.

How do I position these elements? Here is my code so far:

class GazettePageTemplate(PageTemplate):
def __init__(self, id, pageSize=defaultPageSize):
self.pageWidth = pageSize[1]
self.pageHeight = pageSize[0]
print self.pageWidth
print self.pageHeight
frame1 = Frame(0.5*inch,
inch,
self.pageWidth - 10*inch,
self.pageHeight - 3.4*inch, id='frame1')
frame2 = Frame(1.5*inch,
inch,
self.pageWidth - 1*inch,
self.pageHeight - 3.4*inch, id='frame2')
PageTemplate.__init__(self, id, [frame1, frame2]) # note lack of onPage

def beforeDrawPage(self, canv, doc):
#self.canv.drawImage('/root/journal/gazette/paper1.png',0,0,8.5*inch,11*inch)
canv.drawImage('/root/journal/gazette/paper1.png',0,0,11*inch,8.5*inch)
canv.setFillColorCMYK(0,0.5,0.87,0.14)
canv.setFont("Helvetica-Bold", 16.8)
#p.hAlign('CENTER')
canv.drawString(0, 10, "Footer Text")


def some_view(request):
response = HttpResponse(mimetype='application/pdf')
response['Content-Disposition'] = 'attachment; filename=gorilla-gazette.pdf'

buffer = StringIO()

# Our container for 'Flowable' objects
elements = []

# A large collection of style sheets pre-made for us
styles = getSampleStyleSheet()

# A basic document for us to write to 'hello_platypus.pdf'
doc = SimpleDocTemplate(buffer)#'hello_platypus.pdf')
doc.pageTemplates[:] = [GazettePageTemplate('First')]
doc.pagesize=landscape(letter)

from reportlab.rl_config import defaultPageSize

(MAXWIDTH, MAXHEIGHT) = defaultPageSize

#image = Image('/root/journal/gazette/paper1.png')
print MAXWIDTH
print MAXHEIGHT
#elements.append(KeepInFrame(MAXWIDTH, MAXHEIGHT, [image]))
#elements.append(KeepInFrame(11*inch, 19*inch, [image]))
# Create two 'Paragraph' Flowables and add them to our 'elements'
elements.append(Paragraph(sidebar_head, styles['Heading1']))
elements.append(Paragraph(sidebar, styles['Normal']))
elements.append(Paragraph("""Vulputate velit esse molestie
consequat vel, illum dolore eu feugiat nulla! Legere me lius quod ii
legunt saepius claritas est etiam processus dynamicus qui. Ullamcorper
suscipit lobortis nisl ut aliquip ex ea commodo consequat duis autem
vel eum. Eleifend option congue nihil imperdiet doming id quod? Typi
qui nunc nobis videntur parum, clari fiant sollemnes in.
Demonstraverunt lectores sequitur mutationem consuetudium lectorum
mirum est notare. Dolore te feugait nulla facilisi nam liber tempor
cum soluta nobis? Dignissim qui blandit praesent luptatum, zzril
delenit augue? Ad minim veniam quis nostrud exerci tation iriure dolor
in, hendrerit in facilisis at vero eros. Odio duis mazim placerat
facer possim assum typi non habent claritatem insitam est usus
legentis.
""", styles['Normal']))

# Write the document to disk
doc.build(elements)
# Get the value of the StringIO buffer and write it to the response.
pdf = buffer.getvalue()
buffer.close()
response.write(pdf)
return response


Thanks for your help!
Erik


More information about the reportlab-users mailing list