0

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

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

in the above code, i used the different codepages, but my output from the printer is just question mark ""?"" instead of the persian words
i tried the following code,too:

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()

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

Edited by Reverend Jim: Moved to programming forum

2
Contributors
2
Replies
19
Views
3 Months
Discussion Span
Last Post by rproffitt
0

https://reference.epson-biz.com/modules/ref_charcode_en/index.php?content_id=118 seems to tell me this model may or may not have an Arabic character set. Also https://en.wikipedia.org/wiki/Persian_alphabet#Differences_from_Arabic_alphabet is worth adding here as the printer does not have any indication there is a true Persian character set.

Yes I also checked other posts like this -> https://stackoverflow.com/questions/45605440/print-a-persian-file-by-thermal-printer-and-python-escpos-mnodule and https://community.activestate.com/node/21907 but no one is answering.

The long hard fix would be to render a graphic and if the printer supports it, print that graphic.
http://www.epson.com.au/products/brochures/TMT88III.pdf tells me this may be your only fix.

0

PS. I see you are trying to make an image to print, but I don't see if you previewed it to see if it's fine. Also the printer may be very picky about images. Crawl before you walk by using a known good image file.

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.