[reportlab-users] Problem with embedded font, help needed

Marius Gedminas marius at gedmin.as
Wed Aug 26 10:34:56 EDT 2009


On Tue, Aug 25, 2009 at 09:28:26AM -0300, Roberto Alsina wrote:

> On Tuesday 25 August 2009 09:22:23 Marius Gedminas wrote:

> > It would be interesting.

> >

> > The first thing that comes into mind is that maybe you're writing the

> > contents of the StringIO object into a file object opened in text mode

> > on a Windows system, but I'm sure you would notice something like that.

>

> Nope, all Linux all the time here ;-)

>

> Here's the change that "fixed" this (see pdfbuilder.py),

>

> http://code.google.com/p/rst2pdf/source/detail?r=883

>

> and I am pretty sure now the problem is that I am not using StringIO

> correctly.

>

> Before I did this:

>

> sio=StringIO('')

> [create the PDF in sio]

> self.output=unicode(sio.getvalue(),'utf-8','ignore') #This looks fishy!


Precisely. You take a binary string and randomly remove bits of it
(those substrings that aren't valid UTF-8 sequences). Don't do that.


> And here's what now works:

>

> tmpname=tempfile.mktemp()

> [create the PDF in tmpname]

> self.output=open(tmpname).read()


Assuming this is Python 2.x, you get an 8-bit string from file.read(),
so the StringIO-equivalent of

self.output = sio.getvalue()

should also work.


> I am now guessing I am decoding sio.getvalue() to unicode but shouldn't.


Yes.

Marius Gedminas
--
Truth does not demand belief. Scientists do not join hands every Sunday,
singing, 'Yes, gravity is real! I will have faith! I will be strong! I believe
in my heart that what goes up, up, up must come down, down, down. Amen!' If
they did, we would think they were pretty insecure about it. - Dan Barker
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : <http://two.pairlist.net/pipermail/reportlab-users/attachments/20090826/2d6e1d4d/attachment.pgp>


More information about the reportlab-users mailing list