I need to print an image(logo in png) and then receipt below it on ZQ310 via android app over bluetooth but it consuming lots...

E Efkan YILMAZ 3 years 7 months ago
56 2 0

My code is :
BLuetoothPrintActivity.CONNECTION.open();  Bitmap bitmapToPrint = BitmapFactory.decodeResource(context.getResources(), R.drawable.dummylogo);   ZebraPrinter printer = ZebraPrinterFactory.getInstance(BLuetoothPrintActivity.CONNECTION);  ZebraImageAndroid zebraImageToPrint = new ZebraImageAndroid(bitmapToPrint);  byte[] configLabel = createZplReceipt().getBytes();  BLuetoothPrintActivity.CONNECTION.write(configLabel);

BLuetoothPrintActivity.CONNECTION.write("! UTILITIES\r\nIN-MILLIMETERS\r\nSETFF 10 2\r\nPRINT\r\n".getBytes());
  BLuetoothPrintActivity.CONNECTION.write("! UTILITIES\r\nIN-MILLIMETERS\r\nSETFF 10 2\r\nPRINT\r\n".getBytes());

BLuetoothPrintActivity.CONNECTION.close();

private static String createZplReceipt() {
   /*  This routine is provided to you as an example of how to create a variable length label with user specified data.  The basic flow of the example is as follows  Header of the label with some variable data  Body of the label  Loops thru user content and creates small line items of printed material  Footer of the label  As you can see, there are some variables that the user provides in the header, body and footer, and this routine uses that to build up a proper ZPL string for printing.  Using this same concept, you can create one label for your receipt header, one for the body and one for the footer. The body receipt will be duplicated as many items as there are in your variable data  */   String tmpHeader =
   /*  Some basics of ZPL. Find more information here : http://www.zebra.com/content/dam/zebra/manuals/en-us/printer/zplii-pm-v…; ^XA indicates the beginning of a label  ^PW sets the width of the label (in dots)  ^MNN sets the printer in continuous mode (variable length receipts only make sense with variably sized labels)  ^LL sets the length of the label (we calculate this value at the end of the routine)  ^LH sets the reference axis for printing.  You will notice we change this positioning of the 'Y' axis (length) as we build up the label. Once the positioning is changed, all new fields drawn on the label are rendered as if '0' is the new home position  ^FO sets the origin of the field relative to Label Home ^LH  ^A sets font information  ^FD is a field description  ^GB is graphic boxes (or lines)  ^B sets barcode information  ^XZ indicates the end of a label  */   "^XA" +

   "^PON^PW400^MNN^LL%d^LH0,0" + "\r\n" +

   "^FO20,50" + "\r\n" + "^A0,N,50,50" + "\r\n" + "^FDBagScanner^FS" + "\r\n" +

   "^FO20,130" + "\r\n" + "^A0,N,35,35" + "\r\n" + "^FDOFFICIAL RECEIPT^FS" + "\r\n" +

   "^FO20,180" + "\r\n" + "^A0,N,25,25" + "\r\n" + "^FDDriver ID :^FS" + "\r\n" +

   "^FO225,180" + "\r\n" + "^A0,N,25,25" + "\r\n" + "^FDAcme Industries^FS" + "\r\n" +

   "^FO20,220" + "\r\n" + "^A0,N,25,25" + "\r\n" + "^FDDelivery Date:^FS" + "\r\n" +

   "^FO225,220" + "\r\n" + "^A0,N,25,25" + "\r\n" + "^FD%s^FS" + "\r\n" +

   "^FO20,273" + "\r\n" + "^A0,N,30,30" + "\r\n" + "^FDItem^FS" + "\r\n" +

   "^FO280,273" + "\r\n" + "^A0,N,25,25" + "\r\n" + "^FDPrice^FS" + "\r\n" +

   "^FO20,300" + "\r\n" + "^GB350,5,5,B,0^FS";  int headerHeight = 325;   String body = String.format("^LH0,%d", headerHeight);  int heightOfOneLine = 40;  float totalPrice = 0;   Map itemsToPrint = createListOfItems();  int i = 0;  for (String productName : itemsToPrint.keySet()) {
  String price = itemsToPrint.get(productName);   String lineItem = "^FO20,%d" + "\r\n" + "^A0,N,28,28" + "\r\n" + "^FD%s^FS" + "\r\n" + "^FO280,%d" + "\r\n" + "^A0,N,28,28" + "\r\n" + "^FD$%s^FS";   totalPrice += Float.parseFloat(price);  int totalHeight = i++ * heightOfOneLine;   body += String.format(lineItem, totalHeight, productName, totalHeight, price);   }

   long totalBodyHeight = (itemsToPrint.size() + 1) * heightOfOneLine;  long footerStartPosition = headerHeight + totalBodyHeight;   String footer = String.format("^LH0,%d" + "\r\n" +

   "^FO20,1" + "\r\n" + "^GB350,5,5,B,0^FS" + "\r\n" +

   "^FO20,15" + "\r\n" + "^A0,N,40,40" + "\r\n" + "^FDTotal^FS" + "\r\n" +

   "^FO175,15" + "\r\n" + "^A0,N,40,40" + "\r\n" + "^FD$%.2f^FS" + "\r\n" +

   "^FO20,130" + "\r\n" + "^A0,N,45,45" + "\r\n" + "^FDPlease Sign Below^FS" + "\r\n" +

   "^FO20,190" + "\r\n" + "^GB350,200,2,B^FS" + "\r\n" +

   "^FO20,400" + "\r\n" + "^GB350,5,5,B,0^FS" + "\r\n" +

   "^FO20,420" + "\r\n" + "^A0,N,30,30" + "\r\n" + "^FDThanks for choosing us!^FS" + "\r\n" +

   "^FO20,470" + "\r\n" + "^B3N,N,45,Y,N" + "\r\n" + "^FD0123456^FS" + "\r\n" + "^XZ", footerStartPosition, totalPrice);  long footerHeight = 600;  long labelLength = headerHeight + totalBodyHeight + footerHeight;   Date date = new Date();   SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");   String dateString = sdf.format(date);   String header = String.format(tmpHeader, labelLength, dateString);   String wholeZplLabel = String.format("%s%s%s", header, body, footer);  return wholeZplLabel;}

private static Map createListOfItems() {
  String[] names = { "Microwave Oven", "Sneakers (Size 7)", "XL T-Shirt", "Socks (3-pack)", "Blender", "DVD Movie" };   String[] prices = { "79.99", "69.99", "39.99", "12.99", "34.99", "16.99" };   Map retVal = new HashMap();  for (int ix = 0; ix names.length; ix++) {
  retVal.put(names[ix], prices[ix]);   }
   return retVal;}

Please Register or Login to post a reply

2 Replies

E Efkan YILMAZ

Hi Abhishek,
What do you mean by it is consuming empty spaces?  Can you attach  a picture of the label that it is printing?

A Abhishek kumar

Please any help will be gratefull.I am in a great need.

CONTACT
Can’t find what you’re looking for?