使用热敏打印机和python escpos mnodule打印波斯文件

使用热敏打印机和python escpos mnodule打印波斯文件,python,printing,Python,Printing,我想用热敏打印机打印波斯文件。。 我可以很容易地打印英文文件,但我在打印波斯语文本时遇到了这个问题。。 我想我没有做一些原则……我已经学习了python中的unicode编码和解码……但似乎还不够 请引导我 我的代码在python3中: #!/usr/bin/env python # -*- coding: utf-8 -*- # Print an Arabic string to a printer. # Based on example from escpos-php # Dep

我想用热敏打印机打印波斯文件。。 我可以很容易地打印英文文件,但我在打印波斯语文本时遇到了这个问题。。 我想我没有做一些原则……我已经学习了python中的unicode编码和解码……但似乎还不够 请引导我

我的代码在python3中:

    #!/usr/bin/env python
# -*- coding: utf-8 -*-

# Print an Arabic string to a printer.
# Based on example from escpos-php

# Dependencies-
# - pip install wand python-bidi python-escpos
# - sudo apt-get install fonts-hosny-thabit
# - download arabic_reshaper and place in arabic_reshaper/ subfolder

import arabic_reshaper
#from escpos import printer
from escpos.printer import Usb
from bidi.algorithm import get_display
from wand.image import Image as wImage
from wand.drawing import Drawing as wDrawing
from wand.color import Color as wColor

p = Usb(0x04b8,0x0e15,0)

p.codepage="cp720"   #设置解码的类型

# Some variables
#fontPath = "/usr/share/fonts/opentype/fonts-hosny-thabit/Thabit.ttf"
textUtf8 = u"بعض النصوص من جوجل ترجمة"
tmpImage = 'my-text.png'
printWidth = 550

# Get the characters in order
textReshaped = arabic_reshaper.reshape(textUtf8)
textDisplay = get_display(textReshaped)

# PIL can't do this correctly, need to use 'wand'.
# Based on
# https://stackoverflow.com/questions/5732408/printing-bidi-text-to-an-image
im = wImage(width=printWidth, height=36, background=wColor('#ffffff'))
draw = wDrawing()
draw.text_alignment = 'right';
draw.text_antialias = False
draw.text_encoding = 'utf-8'
draw.text_kerning = 0.0
draw.font_size = 36
draw.text(printWidth, 22, textDisplay)
draw(im)
im.save(filename=tmpImage)

# Print an image with your printer library
p.set(align="right")
p.image(tmpImage)
p.cut()
在上面的代码中,我使用了不同的代码页,但是我从打印机输出的只是问号“?”,而不是波斯语 我也尝试了以下代码:

    from escpos.printer import Usb
""" Seiko Epson Corp. Receipt Printer M129 Definitions (EPSON TM-T88IV) """

p = Usb(0x04b8,0x0e15,0)

p.codepage="iso8859_6"  

# Print text
p.text(u"سلام\n")

p.cut()
但是打印机打印的是模糊的字母。。。 我尝试了不同的代码页。但它没有用

在python论坛和Raspberry Pi论坛上似乎是的副本。在python论坛和Raspberry Pi论坛上似乎是的副本。