[reportlab-users] Newbie -- How to center text in a paragraph
jim at qlf.com
Thu Jun 22 16:53:48 EDT 2006
Ok, I've got that all working now, but now I have a couple of other 'funny'
things going on.
1. I have 3 paragraphs in a frame. I set the style on the first one to be
centered and set the other 2 paragraphs to be left justified. But, all
three paragraphs are centered.
section5P1 = Paragraph(s5Text1, styleCentered)
section5P2 = Paragraph(s5Text2, style)
section5P3 = Paragraph(s5Text3, style)
story5 = 
2. In my paragraph text, I was using the <b> and <i> tags to bold and
italicize. It was working fine until I changed my font to Arial. Now none
of my font decoration stuff is working.
pdfmetrics.registerFont(TTFont('Arial Bold', 'arialbd.ttf'))
pdfmetrics.registerFont(TTFont('Arial Bold Italic', 'arialbi.ttf'))
pdfmetrics.registerFont(TTFont('Arial Italic', 'ariali.ttf'))
baseFont = 'Arial'
styleCentered = styles['Normal']
styleCentered.alignment = 1
styleCentered.fontName = baseFont
text = '<b>This is my bold text</b>'
paragraph = Paragraph(text, styleCentered)
When I do this, my text is not bold. If I replace the <b> tags with <font
face="Arial Bold"> then it works.
Quality Liquid Feeds
(608) 341-9896 cell
From: reportlab-users-bounces at reportlab.com
[mailto:reportlab-users-bounces at reportlab.com] On Behalf Of Andy Robinson
Sent: Thursday, June 22, 2006 3:44 PM
To: Support list for users of Reportlab software
Subject: Re: [reportlab-users] Newbie -- How to center text in a paragraph
Jim Steil wrote:
> 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
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",
para = Paragraph(text, style=sty)
reportlab-users mailing list
reportlab-users at reportlab.com
More information about the reportlab-users