How to print Greek Characters with python-escpos

1.2k views Asked by At

PART 1

I am currently trying to get my printer to properly output Greek and not GreekLish for my restaurant ordering system.

I am using python-escpos.

- My code looks like this.

from escpos.printer import Usb
p = Usb(0x471, 0x55, 0, 0x82, 0x2)
p.charcode(code='Greek')
p.text('Καλημέρα \n')
p.cut()
p.close()

- My output looks like this.

failure 1

Is there an issue with my string input? Am I supposed to encode it?

Also, The library works currently in shops. The issue is instead of printing, for example, Καλημερα I have to print Kalimera, greeklish. I need it to look more professional.

Thank you

PART 2

Added the encoding magic still nothing...

from escpos.printer import Usb
from escpos.exceptions import USBNotFoundError
from escpos.magicencode import MagicEncode, Encoder
import requests


resp = requests.get('https://raw.githubusercontent.com/receipt-print-hq/escpos-printer-db/3612db407d02a08acd93a1540f2b4823be3f020e/dist/capabilities.json')
js = resp.json()
encodings = list(js['encodings'].keys())

for encoding in encodings:
    print(encoding)
    try:
        p = Usb(idVendor=0x471, idProduct= 0x55,in_ep=0x82, out_ep=0x02)
        p.magic.force_encoding(encoding)
        p.text(encoding)
        p.text('ΚΑΛΗΜΕΡΑ \n')
            p.cut()
        p.close()
        
    except USBNotFoundError:
        print('printer not connected or on')

    except Exception as e:
        print(e)

My output looks like this...

failure #2

No Greek Goodmorning for me... I believe I am very close. Any other suggestions?

PART 3

how about we enter some command in the second _raw function?

p = Usb(idVendor=0x471, idProduct= 0x55,in_ep=0x82, out_ep=0x02)

ESC = b'\x1b'

p._raw(ESC + b'\x74\x07') # page 28-29 printer manual

p._raw( add something...)  # need to print Καλημερα

p.cut()
p.close()

HELPFULL

  • printer model Alpha TP-80H

  • programmers manual

  • the printer also came with a self-test page.

page 1

page 2

1

There are 1 answers

0
I. Kostas On

Use the charcode and the codepage

The following code works with my NT-5890K printer

p = printer.Usb(0x0416,0x5011, in_ep=0x81, out_ep=0x03)
p.charcode(code='Greek')
p.codepage = 'CP1253''
p.text('Καλημέρα \n')
p.cut()
p.close()