[reportlab-users] How to indent entire paragraphs

Andy Robinson andy at reportlab.com
Sun Nov 19 16:31:23 EST 2006


Saketh wrote:

> Using Platypus, I insert Paragraphs into my story. I need to indent

> these paragraphs - not just the first line, but the entire paragraph.

>

> Like this:

>

> Paragraph 1: Text

> Paragraph 2: Text text text text

> word-wrapped text text text text

> Paragraph 3: text text text

> word-wrapped text text text

>

> I've tried inserting Spacers, but I don't think I'm doing that

> correctly. How can I indent entire paragraphs?


Paragraph styles have 3 useful attributes: leftIndent, rightIndent and
firstLineIndent (in case you want the latter different to leftIndent).
Just create styles with varying leftIndent for each level you need.


If you want to avoid naming one style for each indent level, you can
use a flowable called Indenter; this can be used to indent all
subsequent flowables. Create another one with a negative indent to
cancel things when you're done.

Code can be found below...


- Andy
from reportlab.platypus.doctemplate import Indenter

----------------------------------------------------
class Indenter(FrameActionFlowable):
"""Increases or decreases left and right margins of frame.

This allows one to have a 'context-sensitive' indentation
and makes nested lists way easier.
"""
def __init__(self, left=0, right=0):
self.left = _evalMeasurement(left)
self.right = _evalMeasurement(right)


More information about the reportlab-users mailing list