在pyx画布中插入unicode文本 [英] Inserting a unicode text into pyx canvas

查看:150
本文介绍了在pyx画布中插入unicode文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组UTF-8字符,我想插入一个 PyX 生成的pdf文件。
我已经将# - * - 编码:utf-8 - * - 添加到文件的顶部。代码有点类似于以下内容:

I have a set of UTF-8 characters that I would like to insert into a PyX generated pdf file. I have included # -*- coding: utf-8 -*- to top of the file. The code is somewhat similar to the following:

# -*- coding: utf-8 -*-
c = canvas.canvas()
txt = "u'aあä'"
c.text(2, 2, "ID: %s"%txt)
c.writeEPSfile("filename.eps")

但我仍然无法让我的头脑。

But I still can't get my head around this.

错误:

'ascii' codec can't encode character u'\xae' in position 47: ordinal not in range(128)


推荐答案

也许你可以从babel包中找到一个相同的设置
当我尝试插入德语ä(一个umlaut)时,我遇到同样的错误。我只是添加了德国的巴贝包:

Maybe you can find an according set from the babel package I ran into the same error when I tried to insert the german ä (a umlaut). I simply added the german babel package:

text.preamble(r"\usepackage[ngerman]{babel}")

之后,这是可能的,没有错误:

After that, this was possible without errors:

c.text(12, 34, "äöüßß")

我也使用了一个utf8输入编码,我认为这是必要的。

I also used an utf8 input encoding, I think this it is necessary as well.

进一步阅读:

https://en.wikibooks.org/wiki/LaTeX/Internationalization

https://en.wikibooks.org/wiki/LaTeX/Fonts

这篇关于在pyx画布中插入unicode文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆