[reportlab-users] ValueError: redefining named object
jo
jose.soares at sferacarta.com
Mon Feb 18 07:04:24 EST 2008
I see the line that cause this error is this one:
self.ss['tx'].setFont('OCR', 10)
seems reportlab can performs setFont() only the first time but this happen
only when the font is defined by user.
I wonder if there's a workaround to avoid this error.
def display(self):
self.ss['tx'] = self.ss['cnvs'].beginText()
self.ss['eli'] = self.ss['cnvs'].beginPath()
self.ss['tx'].setFont('OCR', 10)
self.ss['tx'].setHorizScale(100)
self.ss['tx'].setTextOrigin(0,0)
self.ss['tx'].moveCursor(
(self.ss['borderx'] + (self.ss['pxriga'] * 31)),
(self.ss['bordery'] + (self.ss['pxriga'] * 1))
)
self.ss['tx'].textOut("printing...")
self.ss['cnvs'].drawText(self.ss['tx'])
self.ss['cnvs'].showPage()
self.ss['cnvs'].save()
jo
jo ha scritto:
> Hi all,
>
> I added a new font file to reportlab at
> /usr/lib/python2.4/site-packages/reportlab/fonts
> I'm trying to use it but I have some difficulties.
>
> If I call the function to print a line (self.show(txt='printing...',
> x=31, y=1,font='OCR',size=6) )
> the first time it works, but the second time it rises the error:
> ValueError: redefining named object:
> 'toUnicodeCMap:SUBSET+OCRB10PitchBT-Regular+0'
>
>
> here the sample:
> -----------------------------------------------------------------------------------------------
>
> import reportlab
> from reportlab.pdfbase import pdfmetrics
> from reportlab.pdfbase.ttfonts import TTFont
> reportlab.rl_config.warnOnMissingFontGlyphs = 0
> pdfmetrics.registerFont(TTFont('OCR',
> '/usr/lib/python2.4/site-packages/reportlab/fonts/OCR-b___.ttf'))
> from reportlab.pdfgen import canvas
>
> class Fattura:
> def __init__(self,filename):
> self.ss = dict( tx = None ,
> eli = None ,
> cnvs = None ,
> pxriga = 12 ,
> borderx = 10 ,
> bordery = 10 ,
> name=filename ,
> pagesizex = 70 * 12 ,
> pagesizey = 50 * 12 ,
> )
> self.ss['cnvs'] =
> canvas.Canvas(self.ss['name'],pagesize=(self.ss['pagesizex'],self.ss['pagesizey']),bottomup=0)
>
>
> def stampa(self):
> self.ss['tx'] = self.ss['cnvs'].beginText()
> self.ss['eli'] = self.ss['cnvs'].beginPath()
> # this line raises an error if this function is called twice...
> self.show(txt='printing...', x=31, y=1,font='OCR',size=6)
> self.ss['cnvs'].drawText(self.ss['tx'])
> self.ss['cnvs'].showPage()
> self.ss['cnvs'].save()
> return 1
>
> def show(self,txt='',x=None,y=None,font=None,size=None):
> self.ss['tx'].setFont(font, size)
> self.ss['tx'].setHorizScale(100)
> if x is not None and y is not None:
> self.ss['tx'].setTextOrigin(0,0)
> self.ss['tx'].moveCursor(
> (self.ss['borderx'] + (self.ss['pxriga'] * x)),
> (self.ss['bordery'] + (self.ss['pxriga'] * y)) )
> self.ss['tx'].textOut(" "+txt)
>
> fd=open('pippo.pdf','w')
> e=Fattura(fd)
> for ii in range(2):
> ret=e.stampa()
> fd.close()
>
>
> here the error:
>
> # python test.py
> Traceback (most recent call last):
> File "test.py", line 44, in ?
> ret=e.stampa()
> File "test.py", line 29, in stampa
> self.ss['cnvs'].save()
> File "/usr/lib/python2.4/site-packages/reportlab/pdfgen/canvas.py",
> line 831, in save
> self._doc.SaveToFile(self._filename, self)
> File "/usr/lib/python2.4/site-packages/reportlab/pdfbase/pdfdoc.py",
> line 233, in SaveToFile
> f.write(self.GetPDFData(canvas))
> File "/usr/lib/python2.4/site-packages/reportlab/pdfbase/pdfdoc.py",
> line 245, in GetPDFData
> fnt.addObjects(self)
> File "/usr/lib/python2.4/site-packages/reportlab/pdfbase/ttfonts.py",
> line 1040, in addObjects
> pdfFont.ToUnicode = doc.Reference(cmapStream, 'toUnicodeCMap:' +
> baseFontName)
> File "/usr/lib/python2.4/site-packages/reportlab/pdfbase/pdfdoc.py",
> line 475, in Reference
> raise ValueError, "redefining named object: "+repr(name)
> ValueError: redefining named object:
> 'toUnicodeCMap:SUBSET+OCRB10PitchBT-Regular+0'
>
>
>
> anyone knows how to solve this problem?
> thank you all,
>
> j
>
>
>
> _______________________________________________
> 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