Search code examples
javaandroidescpos

How to increase the size of QR code image - print that is compatible with ESC/POS commands


I have successfully print the QR and Text - Print out image given below

Issue - How to Increase the size of QR code image

enter image description here

First QR is my Output!! Need to increase like in the Second QR

My code:

 byte[] INIT = {27, 64};
 byte[] FEED_LINE = {10};
 byte[] SELECT_FONT_A = {27, 33, 0};
 byte[] ALLINEA_CT = {0x1B, 0x61, 0x01};
 byte[] ALLINEA_SELECT = {0x1b, 0x3d, 0x01};
 byte[] FONT_1X = {0x1D, 0x21, 0x00};
 byte[] SET_BAR_CODE_HEIGHT = {29, 104, 100};

                    OutputStream oStream = sock.getOutputStream();
                    oStream.write(INIT);
                    oStream.write(ALLINEA_CT);
                    oStream.write(SET_BAR_CODE_HEIGHT);
                    oStream.write(ALLINEA_CT); 
                    oStream.write(ALLINEA_SELECT);
                    oStream.write(command); //command is byte[] command (QR code)
                    oStream.write(FEED_LINE);

                    oStream.write(ALLINEA_CT); //text to center
                    oStream.write(SELECT_FONT_A);
                    oStream.write(FONT_1X);
                    oStream.write("TABLE : ".getBytes());
                    oStream.write(strTable.getBytes());
                    oStream.write(FEED_LINE);

                    oStream.write(new byte[]{0x1D, 0x56, 0x41, 0x10});
                    oStream.flush();
                    oStream.close();
               

Please let me know how to increase the size of QR.


Solution

  • Not able to increase the size more than 255px with the above way.

    Finally solved the size issue by this library

    implementation 'com.github.DantSu:ESCPOS-ThermalPrinter-Android:3.0.0'
    

    Code

    EscPosPrinter printer = new EscPosPrinter(deviceConnection, 203, 48f, 32);
                        printer
                                .printFormattedText(
                                        "[C]<qrcode size='50'>"+strQr+"</qrcode>\n" +
                                                "[C]\n" +
                                                "[C]<font size='tall'>Table No : "+strTable+"</font>\n"
                                );
    

    You can increase/decrease the size of QR by change the value of size inside <qrcode> tag