Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arabic Text not printing correctly #633

Open
1 task done
BaselAbdallah opened this issue Apr 3, 2024 · 2 comments
Open
1 task done

Arabic Text not printing correctly #633

BaselAbdallah opened this issue Apr 3, 2024 · 2 comments

Comments

@BaselAbdallah
Copy link

I have:

  • searched open and closed issues for duplicates

Bug description

•• Arabic Text not printing correctly:

• when testing this code:
from escpos import printer
x = printer.Network("192.168.192.168")
text = "عصير"
x.text(text)
x.cut()
It printed the text reversed "from left to right like that" and each character separated from the other. It printed like this: "ر ي ص ع"

• Then I tested using the code page "CP864" like this:
from escpos import printer
x = printer.Network("192.168.192.168")
x.charcode(code="CP864")
text = "عصير"
x.text(text)
x.cut()
It printed question marks instead of the Arabic characters. I tried using "CP720" and the result was similar to the first case, printed reversed and separated.

• Then I tried using _raw() to print instead of text() like this:
from escpos import printer
x = printer.Network("192.168.192.168")
x.charcode(code="CP864")
text = عصير"
def print_arabic_text(text):
reversed_text = text[::-1]
return reversed_text
x._raw(f"{print_arabic_text(text)}".encode("Arabic"))
x.cut()
exit()
The result was close to correct Arabic text, but not good enough.

•• How to print correct Arabic text?

Steps to reproduce

  • Tested to print Arabic text without selecting a code page.
  • Used code page "CP864" and "CP720".
  • Used _raw() to print instead of text().

Device info

Printer: Epson TM-T20III

python version: 3.12.2

operating system: Windows 11

@belono
Copy link
Contributor

belono commented May 4, 2024

Hi @BaselAbdallah and welcome to python-escpos!

You can add the profile=’TM-T20II’ parameter to the printer's instance. It will instruct python-escpos which charcode sets are supported by your printer and encode your text string properly.
You can then force your printer to select an specific charcode set, but keep in mind that your printer must support that charcode set.

from escpos import printer
x = printer.Network("192.168.192.168", profile=TM-T20II’)
# x.charcode(code="CP864")
x.charcode(code="CP720")  # Correct
text = "عصير"
x.textln(text)
x.cut()

Does this work for your printer?

EDIT on 11-May: The correct charcode seems to be "CP720"

@belono
Copy link
Contributor

belono commented May 11, 2024

Hi @BaselAbdallah !

I had some time to take a second look at your issue.

It looks like "CP720" is the correct charcode and it is also supported by your printer. You only have to pass the profile="TM-T20II" parameter when instancing the connector and let the magicencode feature auto-detect the string encoding.
It works with the Dummy connector so it should do with the other connectors.

In response to the alignment of the text, python-escpos defaults to left aligned text. Did you try to set the printer to right align the characters?

from escpos import printer

x = printer.Network("192.168.192.168", profile=TM-T20II’)
x.charcode(code="CP720")  # Surely you can omit this command
x.set(align="right")
text = "عصير"
x.textln(text)
x.cut()
x.close()

Please, let us know if this works as many users would find this information useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants