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

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


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,
self.pageWidth - 10*inch,
self.pageHeight - 3.4*inch, id='frame1')
frame2 = Frame(1.5*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):
canv.setFont("Helvetica-Bold", 16.8)
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')]

from reportlab.rl_config import defaultPageSize

(MAXWIDTH, MAXHEIGHT) = defaultPageSize

#image = Image('/root/journal/gazette/paper1.png')
#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
""", styles['Normal']))

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

Thanks for your help!

More information about the reportlab-users mailing list