Printing on bluetooth printers

Example on how to use, to bold the word “Apple”:

‘\x1b\x45\x01’+‘Apple’+’\x1b\x45\x00’

See below for the rest:

    TXT_BOLD_OFF: '\x1b\x45\x00', // Bold font OFF
    TXT_BOLD_ON: '\x1b\x45\x01', // Bold font ON

    TXT_FONT_A: '\x1b\x4d\x00', // Font type A //normal font
    TXT_FONT_B: '\x1b\x4d\x01', // Font type B //small font
    TXT_FONT_C: '\x1b\x4d\x02', // Font type C //normal font

    TXT_NORMAL: '\x1b\x21\x00', // Normal text
    TXT_2HEIGHT: '\x1b\x21\x10', // Double height text
    TXT_2WIDTH: '\x1b\x21\x20', // Double width text
    TXT_4SQUARE: '\x1b\x21\x30', // Double width & height text
1 Like

I am sorry but I am not familiar with the Evolute leopard printer. Is it standard bluetooth serial printer?

I have centerm-c960f device please suggest if the above scenario work on that

Thanks in Advance

its working fine thank you

what is the max font size limit

Sorry, but not sure about styling issues (font size, logo etc)

There must be some way to format the HTML atleast. If someone can help, it will be helpful to many

There are mark downs (see above), but no direct html/css styling. It uses a unicode format

Ok! In POS application, I must be able to print the receipt in table, I can do that with https://ionicframework.com/docs/native/printer/ but then I cannot find my printer.
With bluetooth printer https://ionicframework.com/docs/native/bluetooth-serial/ I can find my printer but cannot style it.
What can I do to get it working?
For me any plugin is fine as long as it works.

Thanks for suggest. Please provide a more Unicode. I try to convert some unicode but did not work. ThankYou

See my response from June 6 above. You have to turn on and turn off for each one

This is the limitation of the bluetooth terminal. You can try to change it to bitmap encode. I am not a specialty in turning it to bitmap encode, but you can try and google it. Sorry could not help :expressionless:

Hi, do you know how I can print via a serial connection to a receipt printer (xprinter xp-c2008) ? Do you know of any github repos that might help me or other resources? I also would like to thank you for your git repo for printing in ionic 2+.

Not sure if its 100% would work, because I have not tried it, but you can try with ionic native serial

In the section where it says

console.log('Serial connection opened');

You can then type

this.serial.write('whatever');

I have not tried it, but do let me know the results.

Hello Friend! I have cloned your project but it does not work anymore :frowning: Could you help me please.

Hi Razmans, I tried ionic serial but I had a lot of problems with it so I decided to switch to bluetooth. May I ask you, regarding the code you shared, how can I go about testing it? Will it work if I test on the android emulator’s bluetooth and the my printer? Or do I need a physical device and build apk each time I try to run the solution?

Thanks!

Hi Razmans,

I tested your code and it works perfectly! I am facing a small problem though! I am trying to print receipts and I am having the problem where when I pass a string which has a header (3 lines), body(5 lines), footer(6 lines) into the print function, it only prints half of the total receipt. I am facing this problem everytime the body is more than 2 lines. For cases where the body is only 2 lines or less then, it is able to print from the header to footer completely. Do you know what might be causing this issue?

I hope to hear from you soon,
Thanks!

Have you tried using buffer?

Hello,

Thank you for your reply! No I haven’t tried using buffer. Is this just a ESC/POS buffer command that I should add in my input string? Currently my string is
var finalReceipt = “Welcome to” + ‘\x20’ + companyName + ‘\x0a’ + “Date:” + ‘\x20’ + this.datetime
+ ‘\x0a’ + “Cashier:” + ‘\x20’ + cashierName + ‘\x0a’ + ‘\x0a’ + receiptItems + ‘\x0a’ + “Subtotal:” + ‘\x20’ + “$” + this.totalPayment + ‘\x0a’
+ “GST:” + ‘\x20’ + “$” + gst + ‘\x0a’ + “Service Charge:” + ‘\x20’ + “$” + svc + ‘\x0a’
+ “Total:”+ ‘\x20’ + “$” + val + ‘\x0a’ + “Amount Received:” + ‘\x20’ + “$” + this.amountReceived + ‘\x0a’ + “Change:”
+ ‘\x20’ + “$” + this.change + ‘\x0a’ + “Payment Type:” + ‘\x20’ + this.paymentType + ‘\x0a’ + footer + ‘\x0a’+ ‘\x0a’

receiptItems in the string is my array of items that I wish to print and the command to clear buffer is ‘\x1b\x40’ so do you suggest I place it in front of receiptItems like ‘\x1b\x40’+receiptItems… to clear the buffer first before I store in the items I wish to print?

Hope to hear from you soon,

Thank you

You have to use the following markdowns:

data={
    LF: '\x0a', //Line feed for new lines
    EOL: '\n', //end of line
    FEED_CONTROL_SEQUENCES: {
        CTL_LF: '\x0a', // Print and line feed
        CTL_FF: '\x0c', // Form feed
        CTL_CR: '\x0d', // Carriage return
        CTL_HT: '\x09', // Horizontal tab
        CTL_VT: '\x0b', // Vertical tab
    },
    LINE_SPACING: {
        LS_DEFAULT: '\x1b\x32',  //Spacing
        LS_SET: '\x1b\x33'  //Spacing
    },
    HARDWARE: {
        HW_INIT: '\x1b\x40', // Clear data in buffer and reset modes
        HW_SELECT: '\x1b\x3d\x01', // Printer select
        HW_RESET: '\x1b\x3f\x0a\x00', // Reset printer hardware
    },
    CASH_DRAWER: {
        CD_KICK_2: '\x1b\x70\x00', // Sends a pulse to pin 2 []
        CD_KICK_5: '\x1b\x70\x01', // Sends a pulse to pin 5 []
    },
    MARGINS: {
        BOTTOM: '\x1b\x4f', // Fix bottom size
        LEFT: '\x1b\x6c', // Fix left size
        RIGHT: '\x1b\x51', // Fix right size
    },
    PAPER: {
        PAPER_FULL_CUT: '\x1d\x56\x00', // Full cut paper
        PAPER_PART_CUT: '\x1d\x56\x01', // Partial cut paper
        PAPER_CUT_A: '\x1d\x56\x41', // Partial cut paper
        PAPER_CUT_B: '\x1d\x56\x42', // Partial cut paper
    },
    TEXT_FORMAT: {
        TXT_NORMAL: '\x1b\x21\x00', // Normal text
        TXT_2HEIGHT: '\x1b\x21\x10', // Double height text
        TXT_2WIDTH: '\x1b\x21\x20', // Double width text
        TXT_4SQUARE: '\x1b\x21\x30', // Double width & height text

        TXT_CUSTOM_SIZE: function(width, height) { // other sizes
            var widthDec = (width - 1) * 16;
            var heightDec = height - 1;
            var sizeDec = widthDec + heightDec;
            return '\x1d\x21' + String.fromCharCode(sizeDec);
        },

        TXT_HEIGHT: {
            1: '\x00',
            2: '\x01',
            3: '\x02',
            4: '\x03',
            5: '\x04',
            6: '\x05',
            7: '\x06',
            8: '\x07'
        },
        TXT_WIDTH: {
            1: '\x00',
            2: '\x10',
            3: '\x20',
            4: '\x30',
            5: '\x40',
            6: '\x50',
            7: '\x60',
            8: '\x70'
        },

        TXT_UNDERL_OFF: '\x1b\x2d\x00', // Underline font OFF
        TXT_UNDERL_ON: '\x1b\x2d\x01', // Underline font 1-dot ON
        TXT_UNDERL2_ON: '\x1b\x2d\x02', // Underline font 2-dot ON
        TXT_BOLD_OFF: '\x1b\x45\x00', // Bold font OFF
        TXT_BOLD_ON: '\x1b\x45\x01', // Bold font ON
        TXT_ITALIC_OFF: '\x1b\x35', // Italic font ON
        TXT_ITALIC_ON: '\x1b\x34', // Italic font ON

        TXT_FONT_A: '\x1b\x4d\x00', // Font type A //normal font
        TXT_FONT_B: '\x1b\x4d\x01', // Font type B //small font
        TXT_FONT_C: '\x1b\x4d\x02', // Font type C //normal font

        TXT_ALIGN_LT: '\x1b\x61\x00', // Left justification
        TXT_ALIGN_CT: '\x1b\x61\x01', // Centering
        TXT_ALIGN_RT: '\x1b\x61\x02', // Right justification
    },
    BARCODE_FORMAT: {
        BARCODE_TXT_OFF: '\x1d\x48\x00', // HRI barcode chars OFF
        BARCODE_TXT_ABV: '\x1d\x48\x01', // HRI barcode chars above
        BARCODE_TXT_BLW: '\x1d\x48\x02', // HRI barcode chars below
        BARCODE_TXT_BTH: '\x1d\x48\x03', // HRI barcode chars both above and below

        BARCODE_FONT_A: '\x1d\x66\x00', // Font type A for HRI barcode chars
        BARCODE_FONT_B: '\x1d\x66\x01', // Font type B for HRI barcode chars

        BARCODE_HEIGHT: function(height) { // Barcode Height [1-255]
            return '\x1d\x68' + String.fromCharCode(height);
        },
        // Barcode Width  [2-6]
        BARCODE_WIDTH: {
            1: '\x1d\x77\x02',
            2: '\x1d\x77\x03',
            3: '\x1d\x77\x04',
            4: '\x1d\x77\x05',
            5: '\x1d\x77\x06',
        },
        BARCODE_HEIGHT_DEFAULT: '\x1d\x68\x64', // Barcode height default:100
        BARCODE_WIDTH_DEFAULT: '\x1d\x77\x01', // Barcode width default:1

        BARCODE_UPC_A: '\x1d\x6b\x00', // Barcode type UPC-A
        BARCODE_UPC_E: '\x1d\x6b\x01', // Barcode type UPC-E
        BARCODE_EAN13: '\x1d\x6b\x02', // Barcode type EAN13
        BARCODE_EAN8: '\x1d\x6b\x03', // Barcode type EAN8
        BARCODE_CODE39: '\x1d\x6b\x04', // Barcode type CODE39
        BARCODE_ITF: '\x1d\x6b\x05', // Barcode type ITF
        BARCODE_NW7: '\x1d\x6b\x06', // Barcode type NW7
        BARCODE_CODE93: '\x1d\x6b\x48', // Barcode type CODE93
        BARCODE_CODE128: '\x1d\x6b\x49', // Barcode type CODE128
    },
    CODE2D_FORMAT: {
        TYPE_PDF417: '\x1b\x5a\x00',
        TYPE_DATAMATRIX: '\x1b\x5a\x01',
        TYPE_QR: '\x1b\x5a\x02',
        CODE2D: '\x1b\x5a',
    },
    IMAGE_FORMAT: {
        S_RASTER_N: '\x1d\x76\x30\x00', // Set raster image normal size
        S_RASTER_2W: '\x1d\x76\x30\x01', // Set raster image double width
        S_RASTER_2H: '\x1d\x76\x30\x02', // Set raster image double height
        S_RASTER_Q: '\x1d\x76\x30\x03', // Set raster image quadruple
    },
    BITMAP_FORMAT: {
        BITMAP_S8: '\x1b\x2a\x00',
        BITMAP_D8: '\x1b\x2a\x01',
        BITMAP_S24: '\x1b\x2a\x20',
        BITMAP_D24: '\x1b\x2a\x21'
    },
    GSV0_FORMAT: {
        GSV0_NORMAL: '\x1d\x76\x30\x00',
        GSV0_DW: '\x1d\x76\x30\x01',
        GSV0_DH: '\x1d\x76\x30\x02',
        GSV0_DWDH: '\x1d\x76\x30\x03'
    }
};

Example of how to use, same way as how you are using it. I would recommend to place everything inside a ‘Mutable buffer’

How I would use mutable buffer:

import {MutableBuffer} from 'mutable-buffer';

buff=new MutableBuffer();

this.buff.write(CMD.TEXT_FORMAT.TXT_ALIGN_CT);
    this.buff.write(CMD.TEXT_FORMAT.TXT_BOLD_ON);
    this.buff.write(CMD.TEXT_FORMAT.TXT_NORMAL);
    this.buff.write(CMD.TEXT_FORMAT.TXT_FONT_A);
    this.buff.write(CMD.TEXT_FORMAT.TXT_BOLD_ON);
    this.buff.write("Razman is super awesome dude");
    this.buff.write(CMD.FEED_CONTROL_SEQUENCES.CTL_LF);
    this.buff.write(CMD.TEXT_FORMAT.TXT_BOLD_OFF);
    this.buff.write(CMD.TEXT_FORMAT.TXT_BOLD_OFF);
    this.buff.write(CMD.TEXT_FORMAT.TXT_FONT_A);
    this.buff.write("Yes he is really awesome");
    this.buff.write(CMD.FEED_CONTROL_SEQUENCES.CTL_LF); //2 lines
    this.buff.write(CMD.FEED_CONTROL_SEQUENCES.CTL_LF);

   //and finally, send this.buff to printer
  this.connectBT(address)
    .subscribe(item_printer=>{
      this.bt_serial.write(this.buff.buffer)
      .then(dataz=>{
        console.log("WRITE SUCCESS",dataz);
        this.buff.clear();
        this.disconnectPrinter();
      });
    },err=>{
      console.log("ERROR",err);
      this.buff.clear();
      this.disconnectPrinter();
    })

Hope that helps

1 Like