Orvil Nordström
Orvil Nordström

Reputation: 325

Java how do you use special ESC characters in a string or txt file when communicating with a printer?

This sounds like a very basic question yet I was unable to find an answer anywhere.

I am using a thermal printer (CT S2000) and here is the manual at page 351.

Here it shows the code for special characters such as å and ö and ä. but it does not show how your supposed to use those characters. Is there any way to use this so that you can print out theese special characters by some escape character ?

Sincerly..

//Orville Nordström.

Upvotes: 0

Views: 1269

Answers (1)

Boann
Boann

Reputation: 50041

I don't know how you send data to the printer, what the API looks like etc, but I'm guessing you send some byte array at some point, so having set code page 437 as the printer's active code page, the table in the manual tells you that the character code of å in that code page is is 0x86, so you stick that in your byte array:

byte[] data = ...;
data[...] = (byte)0x86; // å

Java can do the necessary encoding for this character set automatically though, so you don't need to encode the characters manually:

byte[] data = "String with ƒäñçÿ çhåråctérs".getBytes("CP437");

Upvotes: 1

Related Questions