Page 1 of 1

็Help me! Thai font in esc/pos

Posted: Mon Nov 03, 2014 11:21 am
by upgrade9909
Now I use Tsp650 and using esc/pos version 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")
but when it print out thai font are error like this

how can I solve this problem??

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

Posted: Mon Nov 03, 2014 1:02 pm
by scruss
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:
Reed Zhao is the expert on thermal printing here, but he's very busy right now.


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

Posted: Mon Nov 03, 2014 9:10 pm
by upgrade9909
Thank , scruss
And do you know how to change a font size and image size in python-esc/pos ?

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

Posted: Wed Nov 05, 2014 4:42 am
by scruss
Will this work for you?


Here's what I did:

Code: Select all

# -*- coding: utf-8 -*-
# - 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 ='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.

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

Posted: Wed Jun 29, 2016 7:36 pm
by boyzfunhouse
This work for me. Thanks a lot, Scruss. :)