[reportlab-users] Newbie -- How to center text in a paragraph
Andy Robinson
andy at reportlab.com
Thu Jun 22 16:43:46 EDT 2006
Jim Steil wrote:
> Hi:
>
>
>
> I’m REAL new to reportlab and am trying to center my text in a
> paragraph. I’ve found the XML markup and have the following code:
>
>
>
> styles = getSampleStyleSheet()
>
> style = styles['Normal']
>
> s5Text1 = '<para alignment="1"><i><b>QLF PRESERVATIVES AND MOLD
> INHIBITORS</b></i></para>'
Try '<para alignment="center">'. In xml you can use 'left', 'center',
'centre' (for reactionary Brits), 'right' and 'justify'.
But if you want the whole paragraph to be bold, italic and centered,
it's more efficient to make a style with those properties and create the
paragraph with that style. Typically you want about 10 styles in a
document, and only need the XML markup for intra-paragraph changes. To
go this way we DO use numeric constants and TA_CENTER is 1.
from reportlab.lib.styles import ParagraphStyle
from reportab.lib.enums import TA_LEFT, TA_RIGHT, TA_CENTER, TA_JUSTIFY
sty = ParagraphStyle(name="myStyle", alignment="TA_CENTER",
fontName="Helvetica-BoldOblique")
para = Paragraph(text, style=sty)
- Andy
More information about the reportlab-users
mailing list