PosBox模块通过树莓派的硬件盒子打印出来的中文出现乱码
-
在escpos模块下的constants.py文件中第93行(附近)添加下面一行
TXT_ENC_PC936 ='\x1C\x21\x00'
然后在escpos.py文件的第813行附近添加下面一行:'cp936': TXT_ENC_PC936
最后,在escpos.py文件中的第838行注释掉原来一行附近添加一行:#encoding = 'cp437'<br /> encoding = 'cp936'
即,在constants.py文件中添加对中文的编码支持,蓝后在escpos.py文件中引用新添加的encoding,最后的encode_char看起来大概是这个样子的:def encode_char(char): <br /> """ <br /> Encodes a single utf-8 character into a sequence of <br /> esc-pos code page change instructions and character declarations <br /> """ <br /> char_utf8 = char.encode('utf-8')<br /> encoded = ''<br /> encoding = self.encoding # we reuse the last encoding to prevent code page switches at every character<br /> encodings = {<br /> # TODO use ordering to prevent useless switches<br /> # TODO Support other encodings not natively supported by python ( Thai, Khazakh, Kanjis )<br /> 'cp936': TXT_ENC_PC936,<-----新加的<br /> 'cp437': TXT_ENC_PC437,<br /> 'cp850': TXT_ENC_PC850,<br /> 'cp852': TXT_ENC_PC852,<br /> 'cp857': TXT_ENC_PC857,<br /> 'cp858': TXT_ENC_PC858,<br /> 'cp860': TXT_ENC_PC860,<br /> 'cp863': TXT_ENC_PC863,<br /> 'cp865': TXT_ENC_PC865,<br /> 'cp866': TXT_ENC_PC866,<br /> 'cp862': TXT_ENC_PC862,<br /> 'cp720': TXT_ENC_PC720,<br /> 'iso8859_2': TXT_ENC_8859_2,<br /> 'iso8859_7': TXT_ENC_8859_7,<br /> 'iso8859_9': TXT_ENC_8859_9,<br /> 'cp1254' : TXT_ENC_WPC1254,<br /> 'cp1255' : TXT_ENC_WPC1255,<br /> 'cp1256' : TXT_ENC_WPC1256,<br /> 'cp1257' : TXT_ENC_WPC1257,<br /> 'cp1258' : TXT_ENC_WPC1258,<br /> 'katakana' : TXT_ENC_KATAKANA,<br /> }<br /> remaining = copy.copy(encodings)<br /><br /> if not encoding :<br /> #encoding = 'cp437' <----注释掉<br /> encoding = 'cp936'<br /> ……<br />
然后再重启服务,你就会发现中文好使了。
Good luck! -
https://github.com/fvdsn/py-xml-escpos/pull/5/files
已提交给 py-xml-escpos 不知道官网什么时候能合并 -
[quote author=KevinKong link=topic=17116.msg30412#msg30412 date=1432691680]
[quote author=vFire link=topic=17116.msg30410#msg30410 date=1432651083]
太谢谢了~ 一下子就搞定了,之前联络了odoo的官方支持,他们也还没搞定或者说顾得上搞定,搜遍全网都没找到这个解决方法,兄弟,在上海不,我要请你吃饭。。。!!!版主,你可以来蹭一下~:)
[/quote]
哈哈,客气啦,我在北京不在上海,可以让校长和Joshua代我去吃啊,O(∩_∩)O哈哈~
[/quote]
那我去北京的时候怎么也得找你吃饭~ 把QQ密我~~~ 再次表示感谢~ -
OK , 官网 v8.0 分支已经合并进去了...
到时看看 master v9.0 分支是否合并...
<br / https://github.com/odoo/odoo/commit/8fe042ea917dad6a09fe69ef47ad6d6c4f3a72af br />