[reportlab-users] Problems Printing Dates & Times

Rich Shepard rshepard at appl-ecosys.com
Thu Nov 1 18:32:59 EDT 2007


I want to print the date and time a report is printed using the python
datetime() module. It's not working as expected.

At the head of the file I have
import datetime

Some lines down are:

now = datetime.datetime.now
pg = canvas.Canvas('impWt.pdf', pagesize=LETTER)
pg.setFont('Helvetica-Bold', 13)
pg.drawCentredString(306,760,Title)
pg.setFont('Helvetica', 10)
pg.drawCentredString(306,748,now)

Python apparently can't calculate the string width:

Traceback (most recent call last):
File "impWtForm.py", line 112, in ?
compImpWt()
File "impWtForm.py", line 89, in compImpWt
pg.drawCentredString(306,748,now)
File "/usr/lib/python2.4/site-packages/reportlab/pdfgen/canvas.py", line
1179, in drawCentredString
width = self.stringWidth(text, self._fontname, self._fontsize)
File "/usr/lib/python2.4/site-packages/reportlab/pdfgen/canvas.py", line
1283, in stringWidth
return pdfmetrics.stringWidth(text, fontName, fontSize)
File "/home/rshepard/development/python/reportLab/rl_accel/_rl_accel.c",
line 1102, in stringWidthU
res = PyEval_CallObjectWithKeywords(_o1, _o2, _o3); if(!res)
ERROR_EXIT();
File "/home/rshepard/development/python/reportLab/rl_accel/_rl_accel.c",
line 1145, in _instanceStringWidthU
_o1 = _GetAttrString(text, "decode"); if(!_o1) ERROR_EXIT();
AttributeError: decode

How should I code this?

Rich

--
Richard B. Shepard, Ph.D. | The Environmental Permitting
Applied Ecosystem Services, Inc. | Accelerators(TM)
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863


More information about the reportlab-users mailing list