Tobia
Tobia

Reputation: 9526

Java escpos charset encoding

i have to print a raw text printer where i have to se the codepage charset. I found that the best charset for my application is the IBM858. Now the problem is to encode the strings to this codepage.

I tried this:

test = new String("#$@°\\è^ùàòèì\n".getBytes(),"Cp858");
file.write(test.getBytes());

but chars don't match.

Upvotes: 3

Views: 8207

Answers (3)

Gabriel Glenn
Gabriel Glenn

Reputation: 1264

With ESC/POS printer dealing with international charset you have to :

  • set the code page of the printer : for instance ESC t 40 will select the code page ISO8859-15. i.e. in Java outputStream.write( new byte[]{ 0x1B, 0x74, 40 } );
  • encode the string you want to print with the same code page : outputStream.write(theStringToPrint.getBytes("ISO8859-15"));

You must check with your specific printer the code page available and the number to use in the ESC t n command. The EPSON ESC/POS documentation for the ESC t lists code pages available for EPSON printer.

For EPSON printers, useful documentation is found in the page Character Code Tables for TM printers. Check the Single-byte Characters/Code Pages section.

Don't use the International Character Sets and the ESC r n command : it will replace some ASCII character to be able to print some international character with a ASCII code page, it's outdated.

Upvotes: 5

Tobia
Tobia

Reputation: 9526

Printing with raw text printer i completely solved with this:

new PrintStream(stream,true,"Cp858")

however with

file.write("#$@°\\è^ùàòèì\n".getBytes("Cp858"));

the printer misses some chars, i don't know if it was a printer or java trouble.

Upvotes: 0

McDowell
McDowell

Reputation: 108949

This encodes the UTF-16 string as Cp858:

file.write("#$@°\\è^ùàòèì\n".getBytes("Cp858"));

Upvotes: 2

Related Questions