[reportlab-users] ValueError: redefining named object: 'toUnicodeCMap:SUBSET+ArialMT+0'
reportlab-users@reportlab.com
reportlab-users@reportlab.com
Fri, 29 Oct 2004 13:19:19 -0400
This is a multipart message in MIME format.
--=_alternative 005F48F485256F3C_=
Content-Type: text/plain; charset="US-ASCII"
I'm trying to use truetype fonts w/ ReportLab. I am able to add all of my
frames, however, when I try to save the PDF I get the following traceback:
Traceback (most recent call last):
File "C:\Python23\lib\threading.py", line 436, in __bootstrap
self.run()
File
"\\ispa02\python23\ss_app\erp\thick_gui\IDCardExecDefinitionMaintenance.py",
line 441, in run
einst.test()
File
"\\ispa02\python23\lib\site-packages\ss_prod\ss\IDCard\IDCardExecDriver.py",
line 384, in test
self.renderer.save()
File
"\\ispa02\python23\lib\site-packages\ss_prod\ss\IDCard\IDCardPDFRenderer.py",
line 255, in save
self.generate()
File
"\\ispa02\python23\lib\site-packages\ss_prod\ss\IDCard\IDCardPDFRenderer.py",
line 75, in generate
self.canvas.save()
File "C:\Python23\Lib\site-packages\reportlab\pdfgen\canvas.py", line
749, in save
self._doc.SaveToFile(self._filename, self)
File "C:\Python23\Lib\site-packages\reportlab\pdfbase\pdfdoc.py", line
213, in SaveToFile
fnt.addObjects(self)
File "C:\Python23\Lib\site-packages\reportlab\pdfbase\ttfonts.py", line
966, in addObjects
pdfFont.ToUnicode = doc.Reference(cmapStream, 'toUnicodeCMap:' +
baseFontName)
File "C:\Python23\Lib\site-packages\reportlab\pdfbase\pdfdoc.py", line
449, in Reference
raise ValueError, "redefining named object: "+repr(name)
ValueError: redefining named object: 'toUnicodeCMap:SUBSET+ArialMT+0'
Does anyone have any ideas what may be causing this and a proposed
solution?
Here's the part of the code where I create the TTFont object and register
it:
fontDBO = element.getFontDBO() #this is a
database object that has my font info
fweight = fontDBO.get_weight_name()
fstyle = fontDBO.get_style_name()
fkey = fontDBO.face + fweight + fstyle #face attribute
contains "arial"
if fkey not in self.pstyles.keys():
pstyle = ParagraphStyle({})
pstyle.bulletFontName = fontDBO.face
pstyle.fontSize = fontDBO.points * 0.85
pstyle.bulletFontSize = fontDBO.points * 0.85
pstyle.leading = pstyle.fontSize * 1.2
r, g, b = fontDBO.getColor().Get()
pstyle.textColor = colors.Color(r, g, b)
fmodlist = []
fbold = 0
fital = 0
if fweight == "Bold":
fmodlist.append("bold")
fbold = 1
if fstyle == "Italic":
fmodlist.append("italic")
fital = 1
if len(fmodlist):
pstyle.fontName = fontDBO.face.lower() + " " + "
".join(fmodlist)
else:
pstyle.fontName = fontDBO.face.lower()
isTT = 0
if pstyle.fontName in fontinfo:
isTT = 1
ttffile = fontinfo[pstyle.fontName]
pdfmetrics.registerFont(TTFont(pstyle.fontName, ttffile))
addMapping(fontDBO.face, fbold, fital, pstyle.fontName)
self.pstyles[fkey] = pstyle
else:
pstyle = self.pstyles[fkey]
flow = []
textdata = element.static_text
for line in textdata.split('\n'):
flow.append( Paragraph(line, pstyle) )
self.addFrame(posx, posy, sizew, sizeh, flow)
--=_alternative 005F48F485256F3C_=
Content-Type: text/html; charset="US-ASCII"
<br><font size=2 face="sans-serif">I'm trying to use truetype fonts w/
ReportLab. I am able to add all of my frames, however, when I try
to save the PDF I get the following traceback:</font>
<br>
<br><font size=2 face="sans-serif">Traceback (most recent call last):</font>
<br><font size=2 face="sans-serif"> File "C:\Python23\lib\threading.py",
line 436, in __bootstrap</font>
<br><font size=2 face="sans-serif"> self.run()</font>
<br><font size=2 face="sans-serif"> File "\\ispa02\python23\ss_app\erp\thick_gui\IDCardExecDefinitionMaintenance.py",
line 441, in run</font>
<br><font size=2 face="sans-serif"> einst.test()</font>
<br><font size=2 face="sans-serif"> File "\\ispa02\python23\lib\site-packages\ss_prod\ss\IDCard\IDCardExecDriver.py",
line 384, in test</font>
<br><font size=2 face="sans-serif"> self.renderer.save()</font>
<br><font size=2 face="sans-serif"> File "\\ispa02\python23\lib\site-packages\ss_prod\ss\IDCard\IDCardPDFRenderer.py",
line 255, in save</font>
<br><font size=2 face="sans-serif"> self.generate()</font>
<br><font size=2 face="sans-serif"> File "\\ispa02\python23\lib\site-packages\ss_prod\ss\IDCard\IDCardPDFRenderer.py",
line 75, in generate</font>
<br><font size=2 face="sans-serif"> self.canvas.save()</font>
<br><font size=2 face="sans-serif"> File "C:\Python23\Lib\site-packages\reportlab\pdfgen\canvas.py",
line 749, in save</font>
<br><font size=2 face="sans-serif"> self._doc.SaveToFile(self._filename,
self)</font>
<br><font size=2 face="sans-serif"> File "C:\Python23\Lib\site-packages\reportlab\pdfbase\pdfdoc.py",
line 213, in SaveToFile</font>
<br><font size=2 face="sans-serif"> fnt.addObjects(self)</font>
<br><font size=2 face="sans-serif"> File "C:\Python23\Lib\site-packages\reportlab\pdfbase\ttfonts.py",
line 966, in addObjects</font>
<br><font size=2 face="sans-serif"> pdfFont.ToUnicode = doc.Reference(cmapStream,
'toUnicodeCMap:' + baseFontName)</font>
<br><font size=2 face="sans-serif"> File "C:\Python23\Lib\site-packages\reportlab\pdfbase\pdfdoc.py",
line 449, in Reference</font>
<br><font size=2 face="sans-serif"> raise ValueError, "redefining
named object: "+repr(name)</font>
<br><font size=2 face="sans-serif">ValueError: redefining named object:
'toUnicodeCMap:SUBSET+ArialMT+0'</font>
<br>
<br><font size=2 face="sans-serif">Does anyone have any ideas what may
be causing this and a proposed solution?</font>
<br>
<br><font size=2 face="sans-serif">Here's the part of the code where I
create the TTFont object and register it:</font>
<br>
<br><font size=2 face="sans-serif">
fontDBO = element.getFontDBO()
#this is a database object that has my font
info</font>
<br><font size=2 face="sans-serif">
fweight = fontDBO.get_weight_name()</font>
<br><font size=2 face="sans-serif">
fstyle = fontDBO.get_style_name()</font>
<br><font size=2 face="sans-serif">
fkey = fontDBO.face + fweight + fstyle #face attribute contains "arial"</font>
<br>
<br><font size=2 face="sans-serif">
if fkey not in self.pstyles.keys():</font>
<br><font size=2 face="sans-serif">
pstyle = ParagraphStyle({})</font>
<br><font size=2 face="sans-serif">
pstyle.bulletFontName = fontDBO.face</font>
<br><font size=2 face="sans-serif">
pstyle.fontSize = fontDBO.points * 0.85</font>
<br><font size=2 face="sans-serif">
pstyle.bulletFontSize = fontDBO.points * 0.85</font>
<br><font size=2 face="sans-serif">
pstyle.leading = pstyle.fontSize * 1.2</font>
<br><font size=2 face="sans-serif">
r, g, b = fontDBO.getColor().Get()</font>
<br><font size=2 face="sans-serif">
pstyle.textColor = colors.Color(r, g, b)</font>
<br><font size=2 face="sans-serif">
fmodlist = [] </font>
<br><font size=2 face="sans-serif">
fbold = 0</font>
<br><font size=2 face="sans-serif">
fital = 0</font>
<br><font size=2 face="sans-serif">
if fweight == "Bold":</font>
<br><font size=2 face="sans-serif">
fmodlist.append("bold")</font>
<br><font size=2 face="sans-serif">
fbold = 1</font>
<br><font size=2 face="sans-serif">
if fstyle == "Italic":</font>
<br><font size=2 face="sans-serif">
fmodlist.append("italic")</font>
<br><font size=2 face="sans-serif">
fital = 1</font>
<br><font size=2 face="sans-serif">
if len(fmodlist):</font>
<br><font size=2 face="sans-serif">
pstyle.fontName = fontDBO.face.lower() + " " +
" ".join(fmodlist)</font>
<br><font size=2 face="sans-serif">
else:</font>
<br><font size=2 face="sans-serif">
pstyle.fontName = fontDBO.face.lower()</font>
<br><font size=2 face="sans-serif">
isTT = 0</font>
<br><font size=2 face="sans-serif">
if pstyle.fontName in fontinfo:</font>
<br><font size=2 face="sans-serif">
isTT = 1</font>
<br><font size=2 face="sans-serif">
ttffile = fontinfo[pstyle.fontName]</font>
<br><font size=2 face="sans-serif">
pdfmetrics.registerFont(TTFont(pstyle.fontName, ttffile))</font>
<br><font size=2 face="sans-serif">
addMapping(fontDBO.face, fbold, fital, pstyle.fontName) </font>
<br><font size=2 face="sans-serif">
self.pstyles[fkey] = pstyle</font>
<br><font size=2 face="sans-serif">
else:</font>
<br><font size=2 face="sans-serif">
pstyle = self.pstyles[fkey]</font>
<br>
<br><font size=2 face="sans-serif">
flow = []</font>
<br><font size=2 face="sans-serif">
textdata = element.static_text</font>
<br><font size=2 face="sans-serif">
for line in textdata.split('\n'):</font>
<br><font size=2 face="sans-serif">
flow.append( Paragraph(line, pstyle) )</font>
<br><font size=2 face="sans-serif">
self.addFrame(posx, posy, sizew, sizeh, flow)</font>
--=_alternative 005F48F485256F3C_=--