Search code examples
printingescapingthermal-printerepsonescpos

How to add user defined character set in Thermal printer using Escape sequence?


I want to add Hindi character set into my Thermal printer (Gprinter Model:GP-U80030I) using escape sequence (ESC/POS). I read Escape commands from program manual. In what sequence I should send commands to printer. Commands to be used are:

ESC % n
ESC & y c1 c2 [x1 d1...d(y X x1)]...[xk d1...d(y X xk)]
ESC ? n

I am sending ascii values to printer (ex. ESC - 27, % - 38 etc).


Solution

  • Start with something like this:

     private void defineChars() {
            int[] cmd = new int[5 + 37] ; // already set to 0
            cmd[0] = 0x1b; // ESC
            cmd[1] = 0x26; // &
            cmd[2] = 0x03; // y - height
            cmd[3] = 'A'; // starting char to define, c1, 'A' ..
            cmd[4] = 'A'; // c2, ending character, in this case we define only one
            cmd[5] = 12; // x1, dots in horizontal direction
    
            int shift = 6;
    
            // fill the matrix as you wish..
            // 'A' -> black square
            for (int i = 0; i < 36; i++) {
                cmd[i + shift] = 0xff;
            }
            sendCommand(cmd);
    
        }
    

    Don't forget to activate custom fonts with command afterwards:

    private void setCustomChars(boolean set) {
            //select user defined chars
            sendCommand(0x1B, 0x25, (set) ? 1 : 0);
        }
    

    Now, when you send the 'A' character to the printer it will print your custom defined character (black sqare because all the bits are set to 1)..