2009年6月8日月曜日

reportlabでバーコード

http://two.pairlist.net/pipermail/reportlab-users/2008-November/007685.html
を写経してPDFにバーコードに文字列付けてhumanReadableで出力しようとしたところ。
Traceback (most recent call last):
File "./barcode2.py", line 16, in
barcode.drawOn(pdf,50*mm,250*mm)
File "/usr/lib/python2.6/dist-packages/reportlab/platypus/flowables.py", line 105, in drawOn
self._drawOn(canvas)
File "/usr/lib/python2.6/dist-packages/reportlab/platypus/flowables.py", line 89, in _drawOn
self.draw()#this is the bit you overload
File "/usr/lib/python2.6/dist-packages/reportlab/graphics/barcode/common.py", line 219, in draw
self.drawHumanReadable()
File "/usr/lib/python2.6/dist-packages/reportlab/graphics/barcode/common.py", line 164, in drawHumanReadable
self.annotate(x+width/2.,-y,s,fontName,fontSize)
File "/usr/lib/python2.6/dist-packages/reportlab/graphics/barcode/common.py", line 176, in annotate
getattr(canv,func)(text,x,y)
File "/usr/lib/python2.6/dist-packages/reportlab/pdfgen/canvas.py", line 1287, in drawCentredString
width = self.stringWidth(text, self._fontname, self._fontsize)
File "/usr/lib/python2.6/dist-packages/reportlab/pdfgen/canvas.py", line 1392, in stringWidth
(fontSize,self._fontsize)[fontSize is None])
File "/build/buildd/python-reportlab-2.3/src/rl_addons/rl_accel/_rl_accel.c", line 1104, in stringWidthU
File "/build/buildd/python-reportlab-2.3/src/rl_addons/rl_accel/_rl_accel.c", line 1147, in _instanceStringWidthU
AttributeError: decode
とエラー。
調べてみるとcommon.pyの line 176
175: else: func = 'drawString'
176: getattr(canv,func)(text,x,y)
177: canv.restoreState()
でcanvas.pyのline 1283のdrawCentredStringを呼んでいるけれど、定義はこう
1283: def drawCentredString(self, x, y, text):
ということで
176: getattr(canv,func)(x, y, text)
でしょう。

追記:patchを投げておきました。trunkは変わっています。

0 件のコメント:

コメントを投稿