Free knowledge blog: linux, programming, open source, databases, android, frameworks, web and computing in general
In this post I will show you how to print spanish text, text with accents or ñ letters on a thermal printer. I have been searching for this for a long time and now I want to share it.
Printing spanish text or diacritict text is necessary because sometimes the customer’s names or data contains some chars out of the ASCII range.
To make this work, you need a free plugin that I have developed and also you need to share your printer. I encourage you to read the next post first:
The next section assumes that you have already printed the “Hello world” receipt and your printer is working with the plugin as expected.
Some printers support diacritic text or accented text out of the box, you only have to print it. First we create a
ConectorPluginV3 instance and then we call
EscribirTexto which only write text to the printer:
I have a GOOJPRT PT210 printer and it is capable of printing text with diacritics out of the box:
But on the other hand I have a Xprinter-58 and when I try this example it prints chinese chars, so I have another solution below.
Now we will force the printer to print diacritic text by changing the charcode page. Remember that each printer is different and sometimes you will need to enable or disable certain things.
For example, when I want to print spanish text on my ESC POS Xprinter 58, I have to disable chinese char mode by calling
DeshabilitarElModoDeCaracteresChinos and then call
TextoSegunPaginaDeCodigos which generates encoded text through iconv.
TextoSegunPaginaDeCodigos accepts the page number, encoding and text to encode. Then it prints the encoded text to the printer.
In my case, I have used page number 2 but instead of cp860 (as it should be), I specify cp850. With this, I have been able to print next text in my chinese printer:
cp850 con numero 2 ¿EL VELOZ MURCIÉLAGO
HINDÚ COMÍA FELIZ CARDILLO Y KIWI? ¡LA CIGÜEÑA TOCABA EL SAXOFÓN DETRÁS DEL
PALENQUE DE PAJA!.
cp850 con número 2 ¿el veloz murciélago hindú comía feliz
cardillo y kiwi? ¡la cigüeña tocaba el saxofón detrás del palenque de paja!.
And the code looks like this:
If it does not work for you, try another page number combinations. For example you can use charcode page 3 and a different encoding. Anyway, the result receipt is as follows:
Now we can see a real example. Let’s print a sales receipt on a thermal printer, which contains diacritic text:
The source code is as follows:
Another alternative is to define a custom char in a 12×24 grid and then print it. You can design any character.
Learn how to do it in the next link:
The code pages vary depending on the printer. When printing on the printer, it is not necessary to indicate the encoding, but I do it because I convert the characters using iconv.
If it doesn’t work with a specific code page, you should try combining the page number and name or consult the documentation of your printer.
Remember that if you need help, you can send me a message at https://parzibyte.me/#contacto.