Question

I have to print Ruby strings UTF-8 encoded, containing Italian language sentences, to a ESC/POS thermal printer (a printer that accept only ASCII-8BIT (1 byte) charset: http://maxdb.sap.com/doc/7_6/ca/bd35406ee32e34e10000000a155106/content.htm).

BTW, I use Ruby 2.x (on Windows or Linux). I'm confused about how to transcode,

by example let say the string contained in a JSON UTF-8 enccoded on a remote server, or contained in a template file as:

#!/bin/env ruby
# encoding: utf-8

string = "Però non è la città di Barnabù"

I have to translate the string (accented / internationalized 2 bytes) in 1 byte ('ASCII8-BIT' encodded)

Any suggestion to how to do transaltion FROM UTF-8 TO ASCII8-BIT?

I lost myself with methods like: .force_encoding('ASCII-8BIT'), or encode(") ...

EDIT: charset table of Epson TM-T20 printer

many thanks giorgio

Was it helpful?

Solution

I find the solution as:

string.encode "IBM437"

as said in comment, I reread the Epson TM-T20 printer; It's setted with default "code table" number: 0, meanining: "PC437: USA, Standard Europe"

In fact I understand PC437 refer to the 2Code Page 437', see: en.wikipedia.org/wiki/Code_page_437

So i found the interesting gem: github.com/ConradIrwin/encoding-codepage

showing that Code page 437 correspond to charset "IBM437"

Now printer print correctly! I answer here myself to maybe help others.

giorgio

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top