[reportlab-users] RE: Error with Unicode?

Schollnick, Benjamin Benjamin.Schollnick at xerox.com
Fri Jun 17 11:20:51 EDT 2005


Never Mind...

Fixed...

internal_document.RL_Document.append ( Paragraph  (name.encode("UTF-8"),
normal ) )

I forgot about encoding it back to UTF-8....

I realized that might be the solution about 30 seconds after I hit SEND.

By the way, ReportLab, is fantastic...  I still have to sit down and
really
learn Platypus....  So that I can make these reports "fancier"....  But
it really
is a nice toolkit....

I use it quite a bit... 

		- Ben

> -----Original Message-----
> From: Schollnick, Benjamin 
> Sent: Friday, June 17, 2005 11:17 AM
> To: 'Support list for users of Reportlab software'
> Subject: Error with Unicode?
> 
> 
> Folks,
> 
> 	I'm working on an reporting module that I am outputting 
> to PDF...
> 	But I'm still new with Unicode, and I'm running into a 
> unicode issue 
> 	with ReportLab...
> 
> 	(Or I'm missing handling the unicode management....)
> 
> 	Now I'm processing the data from a XML file...
> 	Accessing a Database to processing the audit results...
> 	And exporting a PDF file for each XML file that I'm 
> processing...
> 
> 	(The XML is the raw Audit data, the database contains the raw
> 	license data, and the PDF file contains the check list for the
> 	audit)
> 
> 	I believe the following code...
> 
>     print "processing: ", audit_file_name
>     for x in classifications:
> ##        internal_document.RL_Document.append ( "<B> %s </B>" % x)
>         data = return_classification_in_listing ( x[0], listing)
>         for name in data:
>             normal = ParagraphStyle ('Normal')
> 
>             internal_document.RL_Document.append ( Paragraph 
> (escape(name), normal ) )
> 
>  #           internal_document.RL_Document.append ( name  )
> #
>     internal_document.output_document ( filename,orientation )
> 
> 	is where it is breaking...  Specifically, if 
> 
> 	name = "American Greetings(r) Art"
> 
> 	The "Registered" (r) symbol is causing it to "gack"...
> 	I added the escape(name)  (escape = from 
> xml.sax.saxutils import escape)
> 	in case the (R) symbol is a XML literal.  It will gack 
> with or without the
> 	escape()...
> 
> 	Any suggestions?  The code is working fine for the 
> majority of the cases...
> 	
> 		- Benjamin
> 
> traceback ---
> processing:  .\Audit_USN03811_U233JYHZA658-20050906-082834.xml
> Traceback (most recent call last):
>   File "C:\develope\security\software_listings.py", line 229, in ?
>     main ()
>   File "C:\develope\security\software_listings.py", line 224, in main
>     write_page ( stored_profile, stored_machinename, 
> stored_time, audit_file_nam e, listing, software_Classifications)
>   File "C:\develope\security\software_listings.py", line 118, 
> in write_page
>     orientation )
>   File "rl_wrapper.py", line 124, in output_document
>     onLaterPages =   self.All_Other_Pages )
>   File 
> "C:\develope\Python24\Lib\site-packages\reportlab\platypus\doc
> template.py
> ", line 814, in build
>     BaseDocTemplate.build(self,flowables)
>   File 
> "C:\develope\Python24\Lib\site-packages\reportlab\platypus\doc
> template.py
> ", line 644, in build
>     self.handle_flowable(flowables)
>   File 
> "C:\develope\Python24\Lib\site-packages\reportlab\platypus\doc
> template.py
> ", line 562, in handle_flowable
>     if self.frame.add(f, self.canv, trySplit=self.allowSplitting):
>   File 
> "C:\develope\Python24\Lib\site-packages\reportlab\platypus\fra
> mes.py", li ne 139, in _add
>     flowable.drawOn(canv, self._x + self._leftExtraIndent, y, 
> _sW=aW-w)
>   File 
> "C:\develope\Python24\Lib\site-packages\reportlab\platypus\flo
> wables.py",
>  line 97, in drawOn
>     self._drawOn(canvas)
>   File 
> "C:\develope\Python24\Lib\site-packages\reportlab\platypus\flo
> wables.py",
>  line 82, in _drawOn
>     self.draw()#this is the bit you overload
>   File 
> "C:\develope\Python24\Lib\site-packages\reportlab\platypus\par
> agraph.py",
>  line 474, in draw
>     self.drawPara(self.debug)
>   File 
> "C:\develope\Python24\Lib\site-packages\reportlab\platypus\par
> agraph.py",
>  line 722, in drawPara
>     t_off = dpl( tx, offset, lines[0][0], lines[0][1], 
> noJustifyLast and nLines=
> =1)
>   File 
> "C:\develope\Python24\Lib\site-packages\reportlab\platypus\par
> agraph.py",
>  line 59, in _leftDrawParaLine
>     tx._textOut(join(words),1)
>   File 
> "C:\develope\Python24\Lib\site-packages\reportlab\pdfgen\texto
> bject.py",
> line 311, in _textOut
>     self._code.append('%s%s' % (self._formatText(text), 
> (TStar and ' T*' or ''))
> )
>   File 
> "C:\develope\Python24\Lib\site-packages\reportlab\pdfgen\texto
> bject.py",
> line 306, in _formatText
>     text = self._canvas._escape(text)
>   File 
> "C:\develope\Python24\Lib\site-packages\reportlab\pdfgen\canva
> s.py", line  231, in _escape
>     return _escapePDF(s)
>   File 
> "C:\develope\Python24\Lib\site-packages\reportlab\pdfbase\pdfu
> tils.py", l ine 139, in _escape
>     return join(map(lambda c, d=_ESCAPEDICT: d[c],s),'')
>   File 
> "C:\develope\Python24\Lib\site-packages\reportlab\pdfbase\pdfu
> tils.py", l ine 139, in <lambda>
>     return join(map(lambda c, d=_ESCAPEDICT: d[c],s),'')
> KeyError: u'\xae'
> 
> C:\develope\security>
> 


More information about the reportlab-users mailing list