Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ReportLab, PDF and Latin-1 characters

177 views
Skip to first unread message

Svenne Krap

unread,
Mar 12, 2003, 3:47:24 PM3/12/03
to
Hi - yes, it's me again :)

Being a native danish speaker, we are blessed with three extra letters
:)
Working with pdfgen, i get

<code>
from reportlab.pdfgen import canvas
c = canvas.Canvas("C:\\mypdf.pdf")
c.setFont('Arial',12)
c.setFont('Helvetica',12)
c.drawString(10,10,'זרו')
</code>

but then, I get :

<error>
UnicodeError: ASCII encoding error: ordinal not in range(128)
</error>

How do I manage to get Latin-1 (or even better full unicode) support
in pdfgen ?

Svenne

Svenne Krap

unread,
Mar 12, 2003, 3:51:12 PM3/12/03
to
On Wed, 12 Mar 2003 21:47:24 +0100, Svenne Krap <usene...@krap.dk>
wrote:

>c.setFont('Arial',12)

Ups.. shouldn't have been there

Jarek Zgoda

unread,
Mar 12, 2003, 3:57:53 PM3/12/03
to
Svenne Krap <usene...@krap.dk> pisze:


> Being a native danish speaker, we are blessed with three extra letters
> :)
> Working with pdfgen, i get
>
> <code>
> from reportlab.pdfgen import canvas
> c = canvas.Canvas("C:\\mypdf.pdf")
> c.setFont('Arial',12)
> c.setFont('Helvetica',12)
> c.drawString(10,10,'ćřĺ')

> </code>
>
> but then, I get :
>
> <error>
> UnicodeError: ASCII encoding error: ordinal not in range(128)
> </error>
>
> How do I manage to get Latin-1 (or even better full unicode) support
> in pdfgen ?

ReportLab _is_ latin (1, 2, 9, 15...) compliant, it only needs unicode
string to be passed to text drawing routines. So:
c.drawString(10, 10, unicode('Zażółć gęślą jaźń'.decode('ISO8859-2')))
should write usual Polish compatibility test ;)

--
Jarek Zgoda
http://www.zgoda.biz/ JID:zg...@jabber.atman.pl

Klaus Alexander Seistrup

unread,
Mar 12, 2003, 4:01:12 PM3/12/03
to
Svenne Krap wrote:

><code>
> from reportlab.pdfgen import canvas
> c = canvas.Canvas("C:\\mypdf.pdf")
> c.setFont('Arial',12)
> c.setFont('Helvetica',12)

> c.drawString(10,10,'æøå')


></code>
>
> but then, I get :
>
><error>
> UnicodeError: ASCII encoding error: ordinal not in range(128)
></error>

How about

#v+

>>> utf8 = lambda s: unicode(s, 'iso-8859-1').encode('utf-8')
>>> c.drawString(10, 10, utf8('frække frølår')

#v-

(substitute your input charset for 'iso-8859-1')?

// Klaus

--
><> vandag, môre, altyd saam

Svenne Krap

unread,
Mar 12, 2003, 4:21:31 PM3/12/03
to
On Wed, 12 Mar 2003 20:57:53 +0000 (UTC), Jarek Zgoda
<jzg...@usun.gazeta.pl> wrote:

>c.drawString(10, 10, unicode('Zażółć gęślą jaźń'.decode('ISO8859-2')))

Still same error

Svenne Krap

unread,
Mar 12, 2003, 4:21:43 PM3/12/03
to
On Wed, 12 Mar 2003 21:01:12 +0000 (UTC), Klaus Alexander Seistrup
<sp...@magnetic-ink.dk> wrote:

>#v+
>
>>>> utf8 = lambda s: unicode(s, 'iso-8859-1').encode('utf-8')
>>>> c.drawString(10, 10, utf8('frække frølår')
>
>#v-

Still same error.

Svenne Krap

unread,
Mar 12, 2003, 4:22:06 PM3/12/03
to
Btw. running IDLE on winblows

On Wed, 12 Mar 2003 21:47:24 +0100, Svenne Krap <usene...@krap.dk>
wrote:

>Hi - yes, it's me again :)

Klaus Alexander Seistrup

unread,
Mar 12, 2003, 4:34:41 PM3/12/03
to
Svenne Krap wrote:

> Still same error

Are you sure there's nothing wrong with yout python setup?

It works here if I use

#v+

>>> c.drawString(10, 10, unicode('blåbærgrød', 'iso-8859-1'))

#v-

where 'iso-8859-1' is my input charset.

My environment:

#v+

$ python
Python 2.2.2 (#1, Jan 18 2003, 10:18:59)
[GCC 3.2.2 20030109 (Debian prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> ^D
$

#v-

// Klaus

--
><> unselfish actions pay back better

Svenne Krap

unread,
Mar 12, 2003, 4:50:04 PM3/12/03
to

Does the #v- and #v+ do anything ?
Maybe it's a problem with the windows version ? Maybe it's a
locale-problem.. I am still a newbie :)

Klaus Alexander Seistrup

unread,
Mar 12, 2003, 5:38:33 PM3/12/03
to
Svenne Krap wrote:

> Does the #v- and #v+ do anything ?

They are "verbatim" marks for the slrnน newsreader.

> Maybe it's a problem with the windows version ?
> Maybe it's a locale-problem..

Yes, maybe.


// Klaus

น) http://www.slrn.org/

Andy Robinson

unread,
Mar 13, 2003, 11:42:34 AM3/13/03
to
On Wed, 12 Mar 2003 21:47:24 +0100, in comp.lang.python you wrote:

>Hi - yes, it's me again :)
>
>Being a native danish speaker, we are blessed with three extra letters
>:)
>Working with pdfgen, i get

Well, I wrote pdfgen, and can tell you it doesn't DO Unicode
yet :-) If you pass in an 8-bit string, and the string matches
the encoding of the font, it should work. The default encoding
of the standard fonts is Latin-1.

Exactly what Python are you using? Did you download it
or could it be an in-house build? AFAIR there is a way to enable
'Unicode strings everywhere' either as a compiler option or in
the environment, but I'd have to look at the docs.

Can you just try executing this in a script (with no reportlab in
sight):

myString = 'זרו'
print myString

and see if you get an error?


Also try running reportlab/lib/codecharts.py like this:

C:\code\reportlab\lib>codecharts.py
saved codecharts.pdf

It should generate a PDF document with Latin-1 code
charts on page 1. If not let me know.

Best Regards,

Andy Robinson
(ReportLab Inc)

0 new messages