Search code examples
androidprintingzebra-printerszpl

Zebra printer feeds blank page


Currently i'm trying to print in line print mode using CPCL.Everything prints correctly with mZ320 printers but when it comes to the iMz220 or iMz320 then it prints something and long gap again prints something & gap....so on. Please experts have a look on my coding style(using CPCL) and advice me where i'm doing wrong.

                    if (printerModel.equals("3-inch")) {
              String prntFormat = "! U1 SETLP 0 2 24 " + "! U1 SETBOLD 1 "
                          + "! U1 X" + " " + x + " " + "! U1 Y" + " " + y + " "
                          + strValue;

              strBuff = strBuff.append(prntFormat);
               }

Above here we are appending strBuff with the printing stuffs that i would like to print and when my string buffer is inflated with the instructions we are passing it to zebra printer as follows,

        try {
            zebraPrinterConnection.write(strBuff.toString().getBytes());
        } catch (ZebraPrinterConnectionException e) {
            e.printStackTrace();
        }

Solution

  • Instead of using the code

    if (printerModel.equals("3-inch")) {
              String prntFormat = "! U1 SETLP 0 2 24 " + "! U1 SETBOLD 1 "
                          + "! U1 X" + " " + x + " " + "! U1 Y" + " " + y + " "
                          + strValue;
    
              strBuff = strBuff.append(prntFormat);
               }
    

    we need to write

    String prntformat="! 0 200 200 45 1 T 5 0 10 15 "+ strValue + "PRINT\r\n".