I have a printer and SDK to work with it in Java. Printer working well with english letters and digits but doesn't print correctly special symbols like 'ä' or 'ê'.

I suppose that I need to convert string in charset used by printer. But I don't know what is the charset and has no chanse to get it now.

I run test printing with this simple code:

for (int i = 0; i < 256; i++) {
     byte[] a = new byte[1];
     a[0] = (byte) i;
     printer.print((i+" ").getBytes());

And now I know that 'ä' has code 132 and 'ê' has code 136.

How to find charset name, when I know which code corresponding to symbol?

  • "I don't know what is the charset [of the printer]". Create a list of candidate charsets and then print a test paragraph containing accented characters using each of the candidate charsets. Then observe the printed output to determine which of the candidates is most likely to be correct. – Brandin Dec 18 '16 at 22:31

Characters are one of the most confusing things in computer science. This and the reason that computer science was mostly starting in English speaking countries which adopted the ASCII (American Standard Code for Information Interchange) are responsible for the miserable existence characters have to live in a computer. Chinese and emojis were not in question that time. So while Byte == Letter still is taken synonymous and treated as such by most programming languages and programmers, actually they are two different concepts. Apple had introduced the concept of glyphs in its APIs since a long time, but people are still lazy. And that will certainly not change in the near future. Unicode tried to remedy the lack of varieties in glyphs you can represent in a "character string". So they invented the multi-byte character and opened a can of worms. Instead of making things easier, the situation got worse. People and programming languages mix it all up and everyone who ever dealt with code conversion starts whining along with all those poor creatures.

How could you find out the encoding if you don't know? Well, make a statistical analysis of the text. Decide if you got Unicode or not. If not, make a good guess as to which language the original text is made of (how could you do that). Then fix it with that code page.

TL;DR You can't. You need to be supplied with the right information.

  • Multibyte character sets weren't "invented" by Unicode. They existed long before, e.g. in China and Japan. – Jörg W Mittag Dec 18 '16 at 22:11
  • @JörgWMittag Maybe (I'm no historian), but they only got popular with Unicode. We can't claim China/Japan to be responsible for the "String-disaster". – qwerty_so Dec 19 '16 at 5:44

First I get all supported charsets and filter charsets by one of symbols which printer prints correctly (english 'A' with code 65):

SortedMap<String, Charset> charsets = Charset.availableCharsets();
for (SortedMap.Entry<String, Charset> entry : charsets.entrySet()) {
    try {
        String symbol = "A";
        byte[] bytes = symbol.getBytes(entry.getKey());
        if (((int) bytes[0]) == 65) {
    } catch (Exception e) {

I get short list with suitable charsets. Then I filter it by problem symbols and find necessary charset.

  • Uhm. What's that? A solution to your problem? – qwerty_so Dec 18 '16 at 16:18
  • @ThomasKilian yes, I found needed charset by this way. – BArtWell Dec 18 '16 at 16:26
  • Good luck with that. – qwerty_so Dec 18 '16 at 16:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.