reportlab Flowables / Frames / PageTemplate

251 views Asked by At

I read the documentation for ReportLab and though they have good examples for each individual facet (Frames, Flowables, PageTemplates) I can't find anything to tie them together. I am struggling with how to build a story with a custom page template.

I want to make a pdf that looks like this:

|----------------------------|
| Image1 | Image 2 | Sidebar |
|------------------|         |
| Paragraphs       |         |
|----------------------------|
|Graph (image)               |
|----------------------------|

Setting the frames is fairly trivial:

f_image1 = Frame(0, HEIGHT*2/3, WIDTH/3, HEIGHT/3)
f_image2 = Frame(WIDTH/3, HEIGHT*2/3, WIDTH/3, HEIGHT/3)
f_sidebar = Frame(WIDTH*2/3, HEIGHT/3, WIDTH*2/3, HEIGHT*2/3)
f_paragraphs = Frame(0, HEIGHT/3, WIDTH/3, HEIGHT/3)
f_graph = Frame(0, 0, WIDTH, HEIGHT/3)

page_template = PageTemplate(id='myTemplate', frames=[f_image1, f_image2, f_sidebar, f_paragraphs, f_graph])

But from here, I'm not sure how to connect my story to my page_template in an intuitive way. I want certain text to go into the sidebar, certain text to go into the paragraphs, etc.

I tried putting all my story items into a list (story=[]) but then it didn't have the desired effect as text and/or images didn't go into the desired places.

I'm sure I'm just missing something really trivial, but the documentation doesn't give me any hints. (please note, I don't want to manually place things, as the sidebars/paragraphs will flow into many pages)

Can anyone help?

1

There are 1 answers

0
Lamarche Lam On

Try FrameBreak from reportlab.lib.playtus. Whenever you want to move your flowables to next frame, you can simply story.append(FrameBreak()) but you should make sure the frame has enough room for the flowable.