Discussion:
[reportlab-users] Newbie -- How to center text in a paragraph
Jim Steil
2006-06-22 19:26:10 UTC
Permalink
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>'

section5P1 = Paragraph(s5Text1, style)

story5 = []

story5.append(section5P1)

frame5.addFromList(story5, canvas)



And here is the error I'm getting:



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 251, in ?

processPlant(plant, priceList, priceListDate)

File "C:\svn\Python Misc\priceListN.py", line 190, in processPlant

printBacker(canvas, plantNumber)

File "C:\svn\Python Misc\priceListN.py", line 228, in printBacker

section5P1 = Paragraph(s5Text1, style)

File "C:\Python24\reportlab\platypus\paragraph.py", line 445, in __init__

self._setup(text, style, bulletText, frags, cleanBlockQuotedText)

File "C:\Python24\reportlab\platypus\paragraph.py", line 469, in _setup

raise "xml parser error (%s) in paragraph beginning\n'%s'"\

xml parser error (alignment: invalid value 1) in paragraph beginning

'<para alignment="1"><i><b>QLF '



I'm obviously missing the boat on something here but I can't seem to find
it. Any help would really be appreciated.



-Jim



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://two.pairlist.net/pipermail/reportlab-users/attachments/20060622/54338f8d/attachment.htm
Henrique Romano
2006-06-22 21:22:29 UTC
Permalink
I?m REAL new to reportlab and am trying to center my text in a
styles = getSampleStyleSheet()
style = styles['Normal']
s5Text1 = '<para alignment="1"><i><b>QLF PRESERVATIVES AND MOLD
INHIBITORS</b></i></para>'
section5P1 = Paragraph(s5Text1, style)
story5 = []
story5.append(section5P1)
frame5.addFromList(story5, canvas)
You can try using the "alignment" property of ParagraphStyle, or use
a style that is already aligned (like the 'Title' one).


--
Henrique
Jim Steil
2006-06-22 21:25:43 UTC
Permalink
Is there a doc somewhere that details all of the styles available?

-Jim

Jim Steil
IT Manager
Quality Liquid Feeds
(608) 935-2345
(608) 341-9896 cell
-----Original Message-----
From: reportlab-users-***@reportlab.com
[mailto:reportlab-users-***@reportlab.com] On Behalf Of Henrique Romano
Sent: Thursday, June 22, 2006 3:17 PM
To: Support list for users of Reportlab software
Subject: Re: [reportlab-users] Newbie -- How to center text in a paragraph
Post by Jim Steil
I'm REAL new to reportlab and am trying to center my text in a
styles = getSampleStyleSheet()
style = styles['Normal']
s5Text1 = '<para alignment="1"><i><b>QLF PRESERVATIVES AND MOLD
INHIBITORS</b></i></para>'
section5P1 = Paragraph(s5Text1, style)
story5 = []
story5.append(section5P1)
frame5.addFromList(story5, canvas)
You can try using the "alignment" property of ParagraphStyle, or use
a style that is already aligned (like the 'Title' one).


--
Henrique
Henrique Romano
2006-06-22 21:48:13 UTC
Permalink
Post by Jim Steil
Is there a doc somewhere that details all of the styles available?
You can take a look at the userguide (chapter 6 describes
paragraphs and styles), also you can see all the styles
available on getSampleStyleSheet() through .list() method

--
Henrique
Andy Robinson
2006-06-22 21:43:54 UTC
Permalink
I?m REAL new to reportlab and am trying to center my text in a
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
Jim Steil
2006-06-22 21:54:11 UTC
Permalink
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 = []
story5.append(section5P1)
story5.append(Spacer(1, 0.15*inch))
story5.append(section5P2)
story5.append(Spacer(1, 0.15*inch))
story5.append(section5P3)
frame5.addFromList(story5, canvas)

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', 'arial.ttf'))
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.

-Jim

Jim Steil
IT Manager
Quality Liquid Feeds
(608) 935-2345
(608) 341-9896 cell

-----Original Message-----
From: reportlab-users-***@reportlab.com
[mailto:reportlab-users-***@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
Post by Jim Steil
I'm REAL new to reportlab and am trying to center my text in a
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
Andy Robinson
2006-06-22 22:17:51 UTC
Permalink
Post by Jim Steil
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)
Looking below, my hunch is that you have modified the normal style
in the standard stylesheet to be centered, and 'styleCenteredd' and
'style' are references to the same centered object. You should actually
create a new style object.
Post by Jim Steil
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', 'arial.ttf'))
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)
What you have done here is to register 4 fonts, but as yet it has no
knowledge that they are in the same 'family', so it doesn't know what to
do when encountering a <b> or <i> tag. The system has builtin knowledge
of the 'font families' for Helvetica, Courier and Times but no others.
So you need to tell it which combinations of facename/bold/italic map to
which actual font files:

from reportlab.lib.fonts import addMapping
addMapping('Arial', 0, 0, 'Arial')
addMapping('Arial', 0, 1, 'Arial Italic')
addMapping('Arial', 1, 0, 'Arial Bold')
addMapping('Arial', 1, 1, 'Arial Bold Italic')

The user guide mentions this for Rina, which is a poor example
as there were no variants and all we wanted to do was allow <b> and <i>
through harmlessly.

- Andy
Jim Steil
2006-06-22 22:20:20 UTC
Permalink
Thanks everyone for all the help. Now I've got enough to go on to get it
all to work the way I need it to.

-Jim

Jim Steil
IT Manager
Quality Liquid Feeds
(608) 935-2345
(608) 341-9896 cell

-----Original Message-----
From: reportlab-users-***@reportlab.com
[mailto:reportlab-users-***@reportlab.com] On Behalf Of Andy Robinson
Sent: Thursday, June 22, 2006 4:18 PM
To: Support list for users of Reportlab software
Subject: Re: [reportlab-users] Newbie -- How to center text in a paragraph
Post by Jim Steil
Ok, I've got that all working now, but now I have a couple of other
'funny'
Post by Jim Steil
things going on.
1. I have 3 paragraphs in a frame. I set the style on the first one to
be
Post by Jim Steil
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)
Looking below, my hunch is that you have modified the normal style
in the standard stylesheet to be centered, and 'styleCenteredd' and
'style' are references to the same centered object. You should actually
create a new style object.
Post by Jim Steil
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
Post by Jim Steil
of my font decoration stuff is working.
pdfmetrics.registerFont(TTFont('Arial', 'arial.ttf'))
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)
What you have done here is to register 4 fonts, but as yet it has no
knowledge that they are in the same 'family', so it doesn't know what to
do when encountering a <b> or <i> tag. The system has builtin knowledge
of the 'font families' for Helvetica, Courier and Times but no others.
So you need to tell it which combinations of facename/bold/italic map to
which actual font files:

from reportlab.lib.fonts import addMapping
addMapping('Arial', 0, 0, 'Arial')
addMapping('Arial', 0, 1, 'Arial Italic')
addMapping('Arial', 1, 0, 'Arial Bold')
addMapping('Arial', 1, 1, 'Arial Bold Italic')

The user guide mentions this for Rina, which is a poor example
as there were no variants and all we wanted to do was allow <b> and <i>
through harmlessly.

- Andy
Jim Steil
2006-06-23 15:57:41 UTC
Permalink
Ok, I tried the addMappings for the Arial font. Now it works in that it
does bold and italicize when asked, but it is doing it with the wrong font.
I have the following code:

pdfmetrics.registerFont(TTFont('Arial', 'arial.ttf'))
pdfmetrics.registerFont(TTFont('Arial Bold', 'arialbd.ttf'))
pdfmetrics.registerFont(TTFont('Arial Bold Italic', 'arialbi.ttf'))
pdfmetrics.registerFont(TTFont('Arial Italic', 'ariali.ttf'))

addMapping('Arial', 0, 0, 'Arial')
addMapping('Arial', 0, 1, 'Arial Italic')
addMapping('Arial', 1, 0, 'Arial Bold')
addMapping('Arial', 1, 1, 'Arial Bold Italic')

Then in my text I used the <b> and <i> tags to turn it off and on. The
problem is not that it is bolding and italicizing the text, but not with the
Arial font. It is reverting back to a Times-Roman (I think) font.

Any ideas of what I'm doing wrong?

-Jim

Jim Steil
IT Manager
Quality Liquid Feeds
(608) 935-2345
(608) 341-9896 cell
-----Original Message-----
From: reportlab-users-***@reportlab.com
[mailto:reportlab-users-***@reportlab.com] On Behalf Of Andy Robinson
Sent: Thursday, June 22, 2006 4:18 PM
To: Support list for users of Reportlab software
Subject: Re: [reportlab-users] Newbie -- How to center text in a paragraph
Post by Jim Steil
Ok, I've got that all working now, but now I have a couple of other
'funny'
Post by Jim Steil
things going on.
1. I have 3 paragraphs in a frame. I set the style on the first one to
be
Post by Jim Steil
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)
Looking below, my hunch is that you have modified the normal style
in the standard stylesheet to be centered, and 'styleCenteredd' and
'style' are references to the same centered object. You should actually
create a new style object.
Post by Jim Steil
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
Post by Jim Steil
of my font decoration stuff is working.
pdfmetrics.registerFont(TTFont('Arial', 'arial.ttf'))
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)
What you have done here is to register 4 fonts, but as yet it has no
knowledge that they are in the same 'family', so it doesn't know what to
do when encountering a <b> or <i> tag. The system has builtin knowledge
of the 'font families' for Helvetica, Courier and Times but no others.
So you need to tell it which combinations of facename/bold/italic map to
which actual font files:

from reportlab.lib.fonts import addMapping
addMapping('Arial', 0, 0, 'Arial')
addMapping('Arial', 0, 1, 'Arial Italic')
addMapping('Arial', 1, 0, 'Arial Bold')
addMapping('Arial', 1, 1, 'Arial Bold Italic')

The user guide mentions this for Rina, which is a poor example
as there were no variants and all we wanted to do was allow <b> and <i>
through harmlessly.

- Andy
Jim Steil
2006-06-23 16:04:35 UTC
Permalink
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-***@reportlab.com
[mailto:reportlab-users-***@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
Post by Jim Steil
I'm REAL new to reportlab and am trying to center my text in a
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
Henrique Romano
2006-06-23 16:24:54 UTC
Permalink
Post by Jim Steil
styleCentered = ParagraphStyle(name="centeredStyle", alignment="TA_CENTER",
TA_CENTER isn't a string, it is a constant.

from reportlab.lib.enums import TA_CENTER
styleCentered = ParagraphStyle(name="centeredStyle", alignment=TA_CENTER)


Henrique
Andy Robinson
2006-06-23 16:32:47 UTC
Permalink
In this example change
alignment="TA_CENTER"
to
alignment=TA_CENTER
Assuming you have imported the name. In Python-land we use a numeric constant (you could use 1 but it is cryptic) and in xml-land we use "center",

Hope this gets you there,

Andy
-----Original Message-----
From: "Jim Steil" <***@qlf.com>
Date: Fri, 23 Jun 2006 10:04:11
To:"'Support list for users of Reportlab software'"<reportlab-***@reportlab.com>
Subject: RE: [reportlab-users] Newbie -- How to center text in a paragraph

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-***@reportlab.com
[mailto:reportlab-users-***@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
Post by Jim Steil
I'm REAL new to reportlab and am trying to center my text in a
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
Jim Steil
2006-06-23 16:40:40 UTC
Permalink
Well, that fixed everything. The other message regarding the font not
showing correctly in bold and italics was related. It is working as
expected now.

-Jim

Jim Steil
IT Manager
Quality Liquid Feeds
(608) 935-2345
(608) 341-9896 cell

-----Original Message-----
From: reportlab-users-***@reportlab.com
[mailto:reportlab-users-***@reportlab.com] On Behalf Of Andy Robinson
Sent: Friday, June 23, 2006 10:27 AM
To: Reportlab-***@Reportlab. Com
Subject: Re: [reportlab-users] Newbie -- How to center text in a paragraph

In this example change
alignment="TA_CENTER"
to
alignment=TA_CENTER
Assuming you have imported the name. In Python-land we use a numeric
constant (you could use 1 but it is cryptic) and in xml-land we use
"center",

Hope this gets you there,

Andy
-----Original Message-----
From: "Jim Steil" <***@qlf.com>
Date: Fri, 23 Jun 2006 10:04:11
To:"'Support list for users of Reportlab
software'"<reportlab-***@reportlab.com>
Subject: RE: [reportlab-users] Newbie -- How to center text in a paragraph

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-***@reportlab.com
[mailto:reportlab-users-***@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
Post by Jim Steil
I'm REAL new to reportlab and am trying to center my text in a
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

Loading...