Python Forum
print a persian file by thermal printer and python-escpos mnodule
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
print a persian file by thermal printer and python-escpos mnodule
#1
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

my code is in 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()
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:
#coding=utf8

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
Reply


Messages In This Thread
print a persian file by thermal printer and python-escpos mnodule - by gray - Aug-10-2017, 05:12 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Trying to send file to printer with no results. chob_thomas 2 3,421 Dec-21-2022, 07:12 AM
Last Post: Pedroski55
  Saving the print result in a text file Calli 8 1,893 Sep-25-2022, 06:38 PM
Last Post: snippsat
  How do you marshal the default printer setup to print? hammer 0 1,294 May-29-2022, 02:54 PM
Last Post: hammer
  Can you print a string variable to printer hammer 2 1,994 Apr-30-2022, 11:48 PM
Last Post: hammer
  failing to print not matched lines from second file tester_V 14 6,196 Apr-05-2022, 11:56 AM
Last Post: codinglearner
  Print to a New Line when Appending File DaveG 0 1,239 Mar-30-2022, 04:14 AM
Last Post: DaveG
Sad Want to Save Print output in csv file Rasedul 5 11,089 Jan-11-2022, 07:04 PM
Last Post: snippsat
  Convert legacy print file to XLSX file davidm 1 1,834 Oct-17-2021, 05:08 AM
Last Post: davidm
  Why it does not print(file.read()) Rejaul84 1 2,364 Jul-01-2021, 10:37 PM
Last Post: bowlofred
  get two characters, count and print from a .txt file Pleiades 9 3,432 Oct-05-2020, 09:22 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020