[reportlab-users] Newbie -- How to center text in a paragraph
Jim Steil
jim at qlf.com
Fri Jun 23 11:04:11 EDT 2006
I'm having a problem yet with the centering. I have the following code:
styleCentered = ParagraphStyle(name="centeredStyle", alignment="TA_CENTER",
fontName=baseFont)
line1 = Paragraph('24-Hour Delivery Service on', styleCentered)
story1 = []
story1.append(line1)
frame1.addFromList(story1, canvas)
Which produces the following exception:
Traceback (most recent call last):
File
"C:\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py",
line 310, in RunScript
exec codeObject in __main__.__dict__
File "C:\svn\Python Misc\priceListN.py", line 385, in ?
processPlant(plant, priceList, priceListDate)
File "C:\svn\Python Misc\priceListN.py", line 198, in processPlant
printBacker(canvas, plantNumber)
File "C:\svn\Python Misc\priceListN.py", line 258, in printBacker
frame1.addFromList(story1, canvas)
File "C:\Python24\reportlab\platypus\frames.py", line 202, in addFromList
if self.add(head,canv,trySplit=0):
File "C:\Python24\reportlab\platypus\frames.py", line 149, in _add
flowable.drawOn(canv, self._x + self._leftExtraIndent, y, _sW=aW-w)
File "C:\Python24\reportlab\platypus\flowables.py", line 103, in drawOn
self._drawOn(canvas)
File "C:\Python24\reportlab\platypus\flowables.py", line 88, in _drawOn
self.draw()#this is the bit you overload
File "C:\Python24\reportlab\platypus\paragraph.py", line 549, in draw
self.drawPara(self.debug)
File "C:\Python24\reportlab\platypus\paragraph.py", line 848, in drawPara
t_off = dpl( tx, offset, lines[0][0], lines[0][1], noJustifyLast and
nLines==1)
UnboundLocalError: local variable 'dpl' referenced before assignment
Any ideas?
-Jim
Jim Steil
IT Manager
Quality Liquid Feeds
(608) 935-2345
(608) 341-9896 cell
-----Original Message-----
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:
> 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
_______________________________________________
reportlab-users mailing list
reportlab-users at reportlab.com
http://two.pairlist.net/mailman/listinfo/reportlab-users
More information about the reportlab-users
mailing list