print a persian file by thermal printer and python-escpos mnodule

Posted by gray on 2017-08-12 02:45

hello friends...
i want to print a persian file by thermal printer..
i can print an english file esily..but i face the proble while printing persian text..
i think i don't do some principles...i have studied about unicode encodeand decode in python..but it seems it isn't enough
please guide me

in the first code, i used the different codepages, but my output from the printer is just question mark ""?"" instead of the persian words

in the second code
the printer prints the obscure letters...
i tried the different codepages..but it wasn't usefull

#!/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
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)

# Print an image with your printer library

the second code :

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

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


# Print text