upgrade9909
Posts: 7
Joined: Wed Sep 10, 2014 6:39 am

็Help me! Thai font in esc/pos

Mon Nov 03, 2014 11:21 am

Now I use Tsp650 and using esc/pos version 1.0.9
https://pypi.python.org/pypi/python-escpos/1.0.9

this is my code

Code: Select all

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

from escpos import *
import qrcode

Epson = printer.Usb(0x0519,0x0001)
Epson.set(font='a', codepage='cp874', size='2x', align='center')
s = u'ลองตัวอักษรไทย'
Epson.text("Hello World\n")
Epson.text(s)
Epson.cut()
but when it print out thai font are error like this http://s23.postimg.org/ac75oieff/DSC_1344.jpg

how can I solve this problem??

User avatar
scruss
Posts: 3399
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: ็Help me! Thai font in esc/pos

Mon Nov 03, 2014 1:02 pm

Most ESC-POS printers only know 8-bit charater sets. As you're using Unicode, the codes are well outside that range. So you're going to have to use graphics mode.

Now you're using a faster printer than the Sparkfun/Adafruit one, you could take a look at:
  1. Using a TrueType font and rendering it to a bitmap using the Pillow ImageFont module.
  2. Print the bitmap using something like this: esc-pos-image.py.
Reed Zhao is the expert on thermal printing here, but he's very busy right now.

cheers,
Stewart
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.
Pronouns: he/him

upgrade9909
Posts: 7
Joined: Wed Sep 10, 2014 6:39 am

Re: ็Help me! Thai font in esc/pos

Mon Nov 03, 2014 9:10 pm

Thank , scruss
And do you know how to change a font size and image size in python-esc/pos ?

User avatar
scruss
Posts: 3399
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: ็Help me! Thai font in esc/pos

Wed Nov 05, 2014 4:42 am

Will this work for you?

Image

Here's what I did:

Code: Select all

#!/usr/bin/python
# -*- coding: utf-8 -*-
# thaitest.py - thai thermal printing test - scruss, 2014-11-04

from PIL import Image, ImageFont, ImageOps, ImageDraw
from escpos import *

text = u'ลองตัวอักษรไทย'             # Thai for ‘Thai Alphabet’, maybe?
Epson = printer.Serial(devfile='/dev/ttyUSB2')  # <<< change this !!!

# Used Thai font 'Loma', installed by
#   sudo apt-get install fonts-tlwg-loma
# then
#   cp /usr/share/fonts/truetype/tlwg/Loma.ttf .

# Used 36 pt Loma font
font = ImageFont.truetype('Loma.ttf', 36)
box = font.getsize(text)         # work out size of text
# make an image same width as text, but twice the height
image = Image.new('RGB', (box[0], 2 * box[1]))
draw = ImageDraw.Draw(image)
# draw the text at the left edge of the box
draw.text((0, 0), text, font=font)
image = ImageOps.invert(image)   # invert image to black on white
Epson._convert_image(image)      # output image to printer
Let me know if you have any questions.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.
Pronouns: he/him

boyzfunhouse
Posts: 1
Joined: Wed Jun 29, 2016 7:33 pm

Re: ็Help me! Thai font in esc/pos

Wed Jun 29, 2016 7:36 pm

This work for me. Thanks a lot, Scruss. :)

Return to “Python”