eymlo / python-escpos

Automatically exported from code.google.com/p/python-escpos
GNU General Public License v3.0
1 stars 0 forks source link

Thai codepage error #38

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
os:Raspberry Pi

I want to print thai font this is my code

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from escpos import *
import qrcode

Epson = printer.Usb(0x0519,0x0001)
s = u'ตัวอักษรไทย'
Epson.text("Hello World\n")
ss=s.encode('cp874')
Epson.text(ss)
Epson.cut()

but thai letter 'ตัวอักษรไทย' it came out like a added 
picture  
how can I solve it??

Original issue reported on code.google.com by diamondh...@gmail.com on 3 Nov 2014 at 10:55

Attachments:

GoogleCodeExporter commented 9 years ago
As no other answer has been provided to your question, I will show you the more 
time consuming way to accomplish this. You are at least guaranteed an honest 
shot.

I will assume your printer is not sold with Thai fonts. You will have to 
extract the Thai font yourself, and convert each character to a 12x24 cell. 
These cells will be useable in the printers default "Type A" font.

This demo proves Epson will allow you to temporarily substitute the low-order 
ASCII characters:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from escpos import *
#import qrcode

Epson = printer.Usb(0x0519,0x0001)

# define a 12x24 printer custom symbol font
def linedrawncodez ( P, i_offset=0x78, i_length=0x02, j_offset=0x0 ):

  # Graphic mandate: disable real-time commands of the DLE, DC4 prefix
  P._raw('\x1D\x28\x44\x05\x00\x14\x01\x00\x02\x00')

  # Define substitution range
  P._raw(
  char(0x1B)+char(0x26)+
  char(0x03)+
  char( i_offset)+
  char( i_offset + ( i_length - 1 ) )
  )

  # Define substitute type face (only for easy-to-encode 12x24)
  P._raw(
  char(0x0C)+
  char(0x00)+char(0x00)+char(0x00)+
  char(0x00)+char(0x18)+char(0x00)+
  char(0x00)+char(0x18)+char(0x00)+
  char(0x00)+char(0x00)+char(0x00)+
  char(0x00)+char(0x00)+char(0x00)+
  char(0x00)+char(0x18)+char(0x00)+
  char(0x00)+char(0x18)+char(0x00)+
  char(0x00)+char(0x00)+char(0x00)+
  char(0x00)+char(0x00)+char(0x00)+
  char(0x00)+char(0x18)+char(0x00)+
  char(0x00)+char(0x18)+char(0x00)+
  char(0x00)+char(0x00)+char(0x00)+
  char(0x0C)+
  char(0x00)+char(0x00)+char(0x00)+
  char(0x00)+char(0x00)+char(0x00)+
  char(0x00)+char(0x00)+char(0x00)+
  char(0x00)+char(0x00)+char(0x00)+
  char(0x00)+char(0x00)+char(0x00)+
  char(0x33)+char(0x33)+char(0x33)+
  char(0x33)+char(0x33)+char(0x33)+
  char(0x00)+char(0x00)+char(0x00)+
  char(0x00)+char(0x00)+char(0x00)+
  char(0x00)+char(0x00)+char(0x00)+
  char(0x00)+char(0x00)+char(0x00)+
  char(0x00)+char(0x00)+char(0x00)
  )

  # Re-enable real-time commands of the DLE, DC4 prefix
  P._raw('\x1D\x28\x44\x05\x00\x14\x01\x01\x02\x01')

# reset printer
Epson.text(char(0x1b)+char(0x40))

# Declare a Box-Art table, presently 2 characters only:
linedrawncodez(Epson)

# Beginning of line:
Epson.text('yxx 90 xxy = ');

# font custom on
Epson.text('\x1B\x25\x01')

# Will look like: |-- 90 --|
Epson.text('yxx 90 xxy');

# font custom off
Epson.text('\x1B\x25\x00')

# End of line
Epson.text(" <\n");

Epson.cut();

Original comment by syncma...@gmail.com on 16 Feb 2015 at 11:04