[reportlab-users] Fwd: Reportlab and IronPython

Benoit Dupraz dupraz.benoit at gmail.com
Thu Sep 16 03:32:39 EDT 2010


Hi,

First of all, thanks Steve and Tony !
I finally solve the problem !
Tony you are right, changing the format method is the solution. But I still
had an error <http://img811.imageshack.us/img811/1846/error2c.jpg>.
I found by my self the solution. The problem was with the unicode2T1
function.
In pdfmetrics.py you have thix try, except bloc :

try:
from _rl_accel import unicode2T1 #bug sur ironpython?
print 1
except ImportError:
print 2
unicode2T1 = _py_unicode2T1

and it seems that there a problem using this function from _rl_accel.pyd

That's why I write

try:
from _rl_accel import unicode2T1 #bug sur ironpython?
print 1
except ImportError:
print 2
unicode2T1 = _py_unicode2T1
unicode2T1 = _py_unicode2T1

With this, it's apparently working.
Do you any better idea ?

Tanks again Tony and Steve,

Benoit Dupraz
+41 (0)78 909 05 94



2010/9/16 Tony Meyer <tony at spamexperts.com>


> This doesn't have anything to do with IronClad or the Python script

> encoding, or the string being written - the error occurs with simply

> this code:

>

> > from reportlab.pdfgen import canvas

> > c = canvas.Canvas('test.pdf')

> > c.save()

>

> This is a str/unicode issue. FWIW, if ReportLab is patched up to work

> (at least this much) under Python 3, there's a related error:

>

> >>> c.save()

> Traceback (most recent call last):

> File "<stdin>", line 1, in <module>

> File "reportlab/pdfgen/canvas.py", line 1091, in save

> self._doc.SaveToFile(self._filename, self)

> File "reportlab/pdfbase/pdfdoc.py", line 236, in SaveToFile

> f.write(self.GetPDFData(canvas))

> TypeError: 'str' does not support the buffer interface

>

> Tim's message (

> http://two.pairlist.net/pipermail/reportlab-users/2009-August/008699.html)

> from the original thread is a reasonably clear explanation of the

> problem. The patch in that thread should still work, I suspect.

>

> The problem is that in the PDFFile class in pdfdoc.py, the format()

> method converts everything to str. In IronPython, I believe this is

> the same as saying unicode(x, "ascii"). However, the PDF data always

> includes (IIUC as a marker that the file is binary, within a PDF

> comment) a \x93 character, so that fails.

>

> Changing the format() method from:

>

> def format(self, document):

> strings = map(str, self.strings) # final conversion, in case

> of lazy objects

> return string.join(strings, "")

>

> To:

>

> def format(self, document):

> # final conversion, in case of lazy objects

> strings = []

> for s in self.strings:

> if not isinstance(s, types.StringTypes):

> strings.append(str(s))

> else:

> strings.append(s)

> return "".join(strings)

>

> Also removes the problem.

>

> Cheers,

> Tony

> _______________________________________________

> reportlab-users mailing list

> reportlab-users at lists2.reportlab.com

> http://two.pairlist.net/mailman/listinfo/reportlab-users

>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://two.pairlist.net/pipermail/reportlab-users/attachments/20100916/df92d6b9/attachment.html>


More information about the reportlab-users mailing list