[reportlab-users] Bulleted text

Robin Becker robin at reportlab.com
Fri Jun 30 06:18:24 EDT 2006


Saketh Bhamidipati wrote:
> Here is the code that I want to retain:
> 
> Two frames:
> textframe = Frame(2 * inch, 1 * inch, 5.75 * inch, 9 * inch, id = 'TF',
> showBoundary = 1)
> headingframe = Frame(0.5 * inch, 1 * inch, 1.5 * inch, 9 * inch, id = 'HF',
> showBoundary = 1)
> Page template:
> def myPageTemplate(canvas, doc):
>    canvas.saveState()
>    canvas.setFont('Times-Roman', 12)
>    canvas.drawCentredString(PAGE_WIDTH / 2.0, PAGE_HEIGHT - 108, Title)
>    canvas.drawString(PAGE_WIDTH - 2 * inch, PAGE_HEIGHT - inch, Author)
>    canvas.setFont('Times-Roman', 10)
>    canvas.drawCentredString(PAGE_WIDTH / 2.0, inch / 2.0, "%d" % doc.page)
>    canvas.restoreState()
> 
> I need to be able to write text to the textframe, and every time I do 
> that I
> also need to write a heading to the headingframe. Unfortunately, I can't
> seem to find how to combine the low-level features of ReportLab with the
> high-level features of Platypus.
> 
> If I could access the canvas directly in my derived BaseDocTemplate, then I
> would be able to manually write the headings and texts. However, for some
> reason, the canvas is inaccessible in the BaseDocTemplate.
> 
> Here is a semi-pseudocode function that I would like to write, but I'm not
> sure how to implement it:
> def writeText(flowabletext, heading): # heading is a string
>    textframe.write(flowabletext)
>    headingframe.write(heading, flowabletext.getY())
> 
> This is what I need to do:
> 
>   1. Retain the frames and page template that I have written - they are
>   what I need.
>   2. Make a function that writes a block of paragraphs - each paragraph
>   having a bullet - to the textframe, and writes a heading to the heading
>   frame with the same Y-coordinate as the first line of the block of
>   paragraphs.
> 
> I am utterly confused, as the ReportLab documentation and the examples do
> not explain how to do do something like this. Assistance is greatly
> appreciated.

The problem here is that you don't explain (or perhaps care) what happens when 
one or other of the frames fills up. There is an example in the 
test_platypus_general.py script that shows a document template filling parallel 
frames.


The approach there works because we're very careful about the content.
-- 
Robin Becker


More information about the reportlab-users mailing list