Android Question How to print text in graphic mode?

vecino

Well-Known Member
Licensed User
Longtime User
Hi, a customer has some portable bluetooth printers that only print English and Chinese characters.

I need to print these characters:
á é í ó ú Á É Í Ó Ú ñ Ñ ç Ç €

The printers are ESC/POS compatible, but the characters are "cut out" in all the codepages and there are no characters from other languages.

I made a question to the manufacturer and he has indicated that I must use the graphic mode to get these characters to print.
Can anyone explain to me how to do this?
Thank you very much.
 
Last edited:

vecino

Well-Known Member
Licensed User
Longtime User
And here I have printed the entire character set, from 33 to 255:
001.jpg
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
There are other CharSets to test, in my example there are only a few. moreover, as I wrote, you must also try the code pages in combination.

More I can't help you, I hope it's enough to solve
 
Upvote 0

emexes

Expert
Licensed User
To get those characters into a Chinese printer you need to change the CharSet Encoding and possibly the codePage.

This was my thinking too, except that I was sending the ESC t n command directly. I'd found ESC/POS documentation that indicated n = 14 was Windows 1252, but after you tried that and it didn't work, I searched a bit harder and I've found other documentation that indicates n is different for different printers, ie there is no standard. Also, n = 14 is often not listed, which would make our test result of "nothing changed" entirely plausible.

So let's try n = 0 to 20:

B4X:
Dim TestString As String
For I = 1 to 42    'so that fits on one printer line
    TestString = TestString & Chr(128 + I * 3)
Next

For n = 0 to 20
    SendToPrinter(Chr(27) & "t" & Chr(n))    'ESC/POS command to select character code table n
    SendToPrinter(n & ": " & TestString & Chr(13) & Chr(10))
Next


Notes to self:

https://www.sparkag.com.br/wp-conte...AK912-English-Command-Specifications-V1.4.pdf Win 1252 = n = 14
https://aures-support.com/DATA/drivers/Imprimantes/Commande ESCPOS.pdf USA Standard Europe = n = 0 (but is original IBM PC = before Euro)
https://www.toshibatec.nl/upload/docs/jea-03629-esc-pos-specification.pdf PC1252 = n = 9
https://www.starmicronics.com/support/Mannualfolder/escpos_cm_en.pdf WPC1252 = n = 16
https://is.muni.cz/www/stefanak/work/escpos.pdf WPC1252 = n = 16

https://escpos.readthedocs.io/en/latest/font_cmds.html#select-character-code-page-1b-74-rel
https://escpos.readthedocs.io/en/latest/font_cmds.html#select-codepage-1c-7d-26-rel (uses 16-bit direct code page number)
 
Last edited:
Upvote 0

emexes

Expert
Licensed User
Another option is to define characters that I don't need to print what I need, basically only: € ñ Ñ
The accented letters I can omit them, for the moment.
But does anyone have a link on how to define characters?

Using custom-defined characters sounds like an excellent backup plan. But it looks like usually the custom-definitions are stored separately to the built-in fonts, and you'd have to switch back-and-forth between the between the normal font and your custom font, eg this comment:

It's a bit complicated to define whole code page while we need to override only 2 symbols. So we decided to turn on user-defined characters (ESC % 1) before printing special symbols, and turn off (ESC % 0) after that. Not graceful, but easier to implement.
at https://stackoverflow.com/questions...haracter-with-code-126-using-esc-pos-commands

If we can find which built-in code page has the characters you need, then that'd be a far better solution. ?
 
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
B4X:
Dim TestString As String
For I = 1 to 42    'so that fits on one printer line
    TestString = TestString & Chr(128 + I * 3)
Next

For n = 0 to 20
    SendToPrinter(Chr(27) & "t" & Chr(n))    'ESC/POS command to select character code table n
    SendToPrinter(n & ": " & TestString & Chr(13) & Chr(10))
Next

um.jpg
 
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
I just heard back from the manufacturer and it says this:
Hello, printing receipts can only be done in English, and labels can be printed in any language.
But why do they do that? I don't understand.
I mean, you can choose any international configuration to print labels, but not tickets.
It doesn't make any sense.
 
Upvote 0

emexes

Expert
Licensed User
Still, was worth a go.

Is it possible that the method you're using to send characters to the printer, is somehow stripping out the ESC/POS commands?

What happens with:

B4X:
Sub TestPrint(CmdNum As Int, CmdDesc As String)
    Dim OutString As String = CmdDesc
    If CmdNum <> 0 Then
        OutString = Chr(27) & Chr(CmdNum) & "1" & OutString & Chr(27) & Chr(CmdNum) & "0"
    End If
    OutString = OutString & Chr(13) & Chr(10)
    
    SendToPrinter(OutString)
End Sub

TestPrint(0, "Normal")
TestPrint(45, "Underline")
TestPrint(52, "Italics")
TestPrint(69, "Emphasis")
TestPrint(66, "Reverse")
 
Upvote 0

emexes

Expert
Licensed User
Printer Manufacturer said:
Hello, printing receipts can only be done in English, and labels can be printed in any language.

It doesn't make any sense.

I agree it is not clear ? and it would certainly help if they clarified whether "labels" means physical sticky paper labels, or GUI labels on the screen.

So maybe they're saying that text printing can only be done in ASCII/English but if you print a GUI label via snapshot and image print, then you can print any characters that the GUI can render (to the label on the screen).
 
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
I agree it is not clear ? and it would certainly help if they clarified whether "labels" means physical sticky paper labels, or GUI labels on the screen.

So maybe they're saying that text printing can only be done in ASCII/English but if you print a GUI label via snapshot and image print, then you can print any characters that the GUI can render (to the label on the screen).
Yes, I have asked them again to clarify exactly what they are referring to.
 
Upvote 0

emexes

Expert
Licensed User
That's not a problem, thank goodness:
1689933106365.png

Was that printed by directly sending ESC/POS commands eg Chr(27) & "41" for italics?

Or is there a library in the middle that is composing the ESC/POS commands?

And how the heck did it print the circled 7? Is there a command to print any character inside a circle? Or is it a character, like this: ⑦
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
I just heard back from the manufacturer and it says this:

But why do they do that? I don't understand.
I mean, you can choose any international configuration to print labels, but not tickets.
It doesn't make any sense.
I think this is a hardware limitation. The build-in chip or firmware may have limited ROM. If the printer support more commands then the manufacturer may need to use more expensive chip or different chip supplied from the other vendor. Just my 2 cents.
 
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
Was that printed by directly sending ESC/POS commands eg Chr(27) & "41" for italics?

Or is there a library in the middle that is composing the ESC/POS commands?

And how the heck did it print the circled 7? Is there a command to print any character inside a circle? Or is it a character, like this: ⑦
This is the test program I am using. It is Agraham's bluetooth print esc/pos class.
Those 3 characters are "&&&" and yet they come out different on the printer.

B4X:
Dim ESC As String = Chr(27)
    Dim FS As String = Chr(28)
    Dim GS As String = Chr(29)
    
    'Bold and underline don't work well in reversed text
    Dim UNREVERSE As String  = GS & "B" & Chr(0)
    Dim REVERSE As String = GS & "B" & Chr(1)
    
    ' Character orientation. Print upside down from right margin
    Dim UNINVERT As String = ESC & "{0"
    Dim INVERT As String = ESC & "{1"
    
    ' Character rotation clockwise. Not much use without also reversing the printed character sequence
    Dim UNROTATE As String = ESC & "V0"
    Dim ROTATE As String = ESC & "V1"
    
    ' Horizontal tab
    Dim HT As String = Chr(9)
    
    ' Character underline
    Dim ULINE0 As String = ESC & "-0"
    Dim ULINE1 As String = ESC & "-1"
    Dim ULINE2 As String = ESC & "-2"
    
    ' Character emphasis
    Dim BOLD As String = ESC & "E1"
    Dim NOBOLD As String = ESC & "E0"
    
    ' Character height and width
    Dim SINGLE As String = GS & "!" & Chr(0x00)
    Dim HIGH As String = GS & "!" & Chr(0x01)
    Dim WIDE As String = GS & "!" & Chr(0x10)
    Dim HIGHWIDE As String = GS & "!" & Chr(0x11)

B4X:
    Printer1.WriteString(Printer1.REVERSE)
    Printer1.WriteString("Reversed text" & CRLF)
    Printer1.WriteString(Printer1.UNREVERSE)
    Printer1.WriteString(Printer1.INVERT)
    Printer1.WriteString("Normal text £££ " & Chr(99) & CRLF)
    Printer1.WriteString(Printer1.UNINVERT)
    Printer1.WriteString(Printer1.ULINE1 & "Underline 1 " & Printer1.ULINE2 & "Underline 2 " & Printer1.ULINE0 & "Normal" & CRLF)
    Printer1.WriteString("None " & Printer1.BOLD & "Bold " & Printer1.NOBOLD & "None " & CRLF)
    Printer1.WriteString("Single " & Printer1.HIGH & "High " & Printer1.WIDE & "Wide " & Printer1.HIGHWIDE & "Both" & Printer1.SINGLE & CRLF)
    Printer1.LineSpacing = 15
    Printer1.WriteString("Line space half follows" & CRLF)
    Printer1.LineSpacing = 45
    Printer1.WriteString("Line space one and a half follows" & CRLF)
 
Upvote 0

emexes

Expert
Licensed User
This is the test program I am using. It is Agraham's bluetooth print esc/pos class.

Could you give this a burl? It uses .WriteBytes so that we hopefully know precisely what bytes are being sent to the printer, rather than .WriteString which I think is doing some code page translations.

B4X:
Dim TestBytes(42) As Byte
For I = 1 to 42    'so that fits on one printer line
    TestBytes(I - 1) = 32 + I * 5
Next

For n = 0 to 20
    Dim CommandBytes(3) As Byte = Array As Byte(27, 116, n)    'ESC t n
    Printer1.WriteBytes(CommandBytes)

    Dim HeadingString As String = n & ": "
    For I = 0 To HeadingString.Length - 1
        Printer1.WriteBytes(Array As Byte(Asc(HeadingString.CharAt(I))))
    Next I
    
    Dim NewLineBytes(2) As Byte = Array As Byte(13, 10)
    Printer1.WriteBytes(NewLineBytes)
Next
 
Upvote 0

emexes

Expert
Licensed User

Lol... close but no cigar. Sorry. Probably work better if we print the 42 test characters too, by adding the highlighted line:

B4X:
Dim TestBytes(42) As Byte
For I = 1 to 42    'so that fits on one printer line
    TestBytes(I - 1) = 32 + I * 5
Next

For n = 0 to 20
    Dim CommandBytes(3) As Byte = Array As Byte(27, 116, n)    'ESC t n
    Printer1.WriteBytes(CommandBytes)

    Dim HeadingString As String = n & ": "
    For I = 0 To HeadingString.Length - 1
        Printer1.WriteBytes(Array As Byte(Asc(HeadingString.CharAt(I))))
    Next I

    Printer1.WriteBytes(TestBytes)
   
    Dim NewLineBytes(2) As Byte = Array As Byte(13, 10)
    Printer1.WriteBytes(NewLineBytes)
Next
 
Upvote 0
Top