anastaciocintra / escpos-coffee

Java library for ESC/POS printer
https://anastaciocintra.github.io/escpos-coffee
MIT License
280 stars 74 forks source link

Cyrillic symbols printing issue #43

Closed alisherkasimovv closed 4 years ago

alisherkasimovv commented 4 years ago

Hi! Sorry for my English in advance. I have an issue with printing Cyrillic symbols. The code I have written looks like this:

// Printing logo of the company
Bitonal algorithm = new BitonalThreshold(127);
BufferedImage  githubBufferedImage = getImage(image);
EscPosImage escposImage = new EscPosImage(new CoffeeImageImpl(githubBufferedImage), algorithm);

BitImageWrapper imageWrapper = new BitImageWrapper();

imageWrapper.setJustification(EscPosConst.Justification.Left_Default);
pos.write(imageWrapper, escposImage);
pos.feed(5);

// Text styling
Style headStyle = new Style()
                .setFontSize(Style.FontSize._1, Style.FontSize._1)
                .setJustification(EscPosConst.Justification.Center);

pos.setCharacterCodeTable(EscPos.CharacterCodeTable.CP866_Cyrillic_2);
pos.writeLF(headStyle, "Ваш номер очереди:");
pos.feed(1);

This is a one part of the code. Other parts are similar to this except styling and text itself to be printed. I am writing this code on Linux, then checking it on Windows machine, where Xprinter XP-80 is connected.

But all the text after printing is in Chinese or Japanese, idk. Only text in English is correct. I've tried all given options from ChacterCodeTable.

Then tried to print something from different application (Office Word, tried to write clear Java code), and the result is correct. Many thanks in advance.

Link to printed sample

anastaciocintra commented 4 years ago

Hi @alisherkasimovv , this issue have a similar problem

27

you can read to try fix your problem with manual codetable configuration in the last post have explanation and how to to do it.

please, give-me a feed-back see you

anastaciocintra commented 4 years ago

hi @alisherkasimovv, take a look at wiki - charactar code table

maybe you need to use Character code table hack techniche

any question, I'm here. good look

[], Marco

alisherkasimovv commented 4 years ago

Thank you very much for your help!

Issue is rather related with different thing. Yesterday I found this PDF, a step by step printer set up instruction for correct work with international charsets. According to it, I should set DIP switch on the back side of the device (step 1). Changed to state ON, DIP switch will set device character set to "International Character", then it'll print other symbols different from Chinese.

Since I hadn't worked with newly bought devices, I didn't know about that. Now, I'll check this then give feedback. I think code works fine.

anastaciocintra commented 4 years ago

Good news @alisherkasimovv So, the "DIP" configuration on the printer can be the key to solve the problem.

Please, after the tests, give to us the results, its because you can help other programmers that will have similar problems.

see you.

alisherkasimovv commented 4 years ago

Hello, @anastaciocintra

Problem hadn't solved yet. Our printer has no any switches, but has setup options programmatically. After long searches I couldn't do setup, but noticed interesting thing - when I try to print data using pure Java classes, data is printed correctly. All Cyrillic symbols shown correctly.

Since I have little time before production, I've solved problem by printing pre-created PNG file, where I print all the text I need. Of course, this temporary solution is not really effective, so I'll continue searches.

P.S. I've tried to hack, but no results.

Thank you!

anastaciocintra commented 4 years ago

Hey @alisherkasimovv Good idea is yours to solve quickly the problem with png technique.

We have another issue #44 with the same kind of problem, and more detailed answers, principally on diagnosis.

Yeap, may be the printer have a software or firmware to do it.

[], Marco

anastaciocintra commented 4 years ago

@alisherkasimovv , take a look on #44 Graphic2D solution

alisherkasimovv commented 4 years ago

@alisherkasimovv , take a look on #44 Graphic2D solution

@anastaciocintra, Yes, I saw it. My solution is similar in some sense, except saving drawn Strings to PNG file. I've created class where I am drawing all Strings to canvas with fixed sizes using Graphic2D. Then I saved canvas to PNG file and then printing it using escpos-coffee. Now, app is working in production with this solution. I am getting new customer demands, which I will add to next version of the app. That time I'll check printing without intermediate file savings. Until then I am looking for another solutions))