Too many options, or Help with layout

43 views
Skip to first unread message

Steve Young

unread,
Oct 13, 2014, 9:18:16 PM10/13/14
to reportl...@googlegroups.com
I am new to reportlabs, but love the documentation and features so far - great job!

I would like to create a pdf for printing flashcards - something like:
  • Page 1 - Title - large text centered horizontally, and logo a bit below and centered horizontally.
  • Page 2 - Front of card 1, image centered horizontally, a little above center vertically, small text below image (like a caption).
  • Page 3 - Rear of card 1, large text centered horizontally and vertically on page
  • Page 4 (same as page 2 with different content)
  • Page 5 (same as page 3 with different content)
  • and so on to the end of the cards.
  • I may also have static footer content that prints on each card
I have figured out how to embed fonts, create custom page sizes, and a few other bits, but I am getting overwhelmed with paragraphs, frames, tables, styles, etc.  What is a pythonic way to approach this layout?

Thanks.

Mike Driscoll

unread,
Oct 14, 2014, 10:14:20 AM10/14/14
to reportl...@googlegroups.com
Hi Steve,


On Monday, October 13, 2014 8:18:16 PM UTC-5, Steve Young wrote:
I am new to reportlabs, but love the documentation and features so far - great job!


Welcome to Reportlab!

 

If every page is going to have specifically placed elements, then I don't think you need flowables. Do you expect the text to overflow from one page onto another? If so, then you need a flowable like a paragraph, table, etc. If not, then you don't need a flowable and you can just use the canvas.

On the other hand, I really like how easy it is to apply font styles with paragraphs, so I use the paragraph's wrapOn() and drawOn() methods to place the text exactly where I want. Here's a tutorial on the subject that might help you:

http://www.blog.pythonlibrary.org/2012/06/27/reportlab-mixing-fixed-content-and-flowables/

- Mike

Steve Young

unread,
Oct 14, 2014, 11:30:23 AM10/14/14
to reportl...@googlegroups.com
Thanks Mike - believe it or not, I have had that post open since last night and referring to it as I work through the docs!  And some of the other posts on your site have been very helpful.

Maybe I am not understanding the terminology yet.  I do not want anything to flow to another page, but the text that appears on each page can range from 1 character, to a word that has 25 characters, to a sentence with 255 characters, so the text should wrap if it is too long to fit the space.  I want the resulting text to be centered horizontally and vertically, and possibly change the font size to keep the text as large as possible but not overflow the area.

Steve  

Mike Driscoll

unread,
Oct 14, 2014, 2:44:24 PM10/14/14
to reportl...@googlegroups.com
Hi Steve,


On Tuesday, October 14, 2014 10:30:23 AM UTC-5, Steve Young wrote:
Thanks Mike - believe it or not, I have had that post open since last night and referring to it as I work through the docs!  And some of the other posts on your site have been very helpful.


I'm glad you've found them useful.
 

Maybe I am not understanding the terminology yet.  I do not want anything to flow to another page, but the text that appears on each page can range from 1 character, to a word that has 25 characters, to a sentence with 255 characters, so the text should wrap if it is too long to fit the space.  I want the resulting text to be centered horizontally and vertically, and possibly change the font size to keep the text as large as possible but not overflow the area.

Steve  


Then I think using my approach using the paragraph will work for you. You can put pretty much anything in the paragraph and use "<font>" tags to control the size and style of the font. I believe you have to set the alignment for the text like this:

alignment=TA_CENTER

You can import that from reportlab.lib.enums, I think.

Hope that helps!
Mike

Steve Young

unread,
Oct 17, 2014, 10:06:50 AM10/17/14
to reportl...@googlegroups.com
Thanks again.  I set up the LetterMaker sample and have been learning from that.  I will start with Paragraphs and see if that will suffice. 

Steve Young

unread,
Oct 21, 2014, 10:06:44 AM10/21/14
to reportl...@googlegroups.com
I followed the template Mike referred to.  I mostly used paragraphs and tables, and one page also had a frame to help center everything in the center of the page.  You can see the code at http://stackoverflow.com/questions/26351922/reportlab-pdf-layout-guide

Thanks.
Reply all
Reply to author
Forward
0 new messages