ZQ520 - Image print problem (Zebra Android SDK)

We used to use the Zebra RW420 model, together with the GraphicsUtil interface functionality from the Zebra Android SDK, which allowed us to use the printImage() method and send an image to the printer on the fly, together with the rest of the receipt data in CPCL language. The image printing looked like this:

 

com.zebra.sdk.printer.ZebraPrinter printer = ZebraPrinterFactory.getInstance(connection);    System.out.println("x: " + x + " y: " + y + " width: " + width + " height: " + height);   connection.write("! U1 JOURNAL\r\n! U1 SETFF 20 2\r\n".getBytes());    printer.printImage(new ZebraImageAndroid(bitmap), x, y, width, height, false);

 

However, since we switched to Zebra ZQ520 model, the same functionality does not work, and instead of printing an image, the printer prints out a lot of hexadecimal characters. This thread is a duplicate of another thread on this discussion board (https://developer.zebra.com/thread/30659), and on that thread an answer was posted stating that the printer should be manually set to use the ZPL language, and the same code should be tested once again. No more feedback was posted after that.

 

Following the advice above, our code to print an image was changed to:

 

public boolean printImage(final Bitmap bitmap, final String fileName, int x, int y, int width, int height, PrinterLanguage language,    PrintListener listener) { //in this case PrinterLanguage.ZPL was passed into the method   if (connection != null) {   if (connection.isConnected()) {   try {        com.zebra.sdk.printer.ZebraPrinter printer = ZebraPrinterFactory.getInstance(language, connection);  //used to be ZebraPrinterFactory.getInstance(connection) for RW420        printer.printImage(new ZebraImageAndroid(bitmap), x, y, width, height, false);        listener.onPrintSuccess();        return true;    } catch (ConnectionException e) {        listener.onPrintFail();        e.printStackTrace();        try {             connection.close();        } catch (ConnectionException e1) {        e1.printStackTrace();        }   }  finally {        if (bitmap != null && !bitmap.isRecycled()) {        bitmap.recycle();        System.gc();        }   }           } else {   listener.onPrintFail();           }   }   return false; }

 

However, that still did not change the result and the image was printed as hex values. We also tried another approach where the image was stored on the printer first via the following code:

 

com.zebra.sdk.printer.ZebraPrinter printer = ZebraPrinterFactory.getInstance(language, connection); ZebraImageI zebraImage = ZebraImageFactory.getImage(bitmap);  printer.storeImage("E:" + fileName.toUpperCase(), zebraImage, width, height);

 

Unfortunately, the method to store the image on the printer did not change the result - whenever we tried to print the stored image, the same issue happened and a lot of hexadecimal characters were printed out.

 

 

We attempted a third approach, using the ZebraUtilities application. An image was successfully loaded onto the printer via the ZebraUtilities, and afterwards the following code was run to print the image:

 

com.zebra.sdk.printer.ZebraPrinter printer = ZebraPrinterFactory.getInstance(language, connection); printer.getConnection().write(("^XA^FT" + x + "," + y + "^XGSIMPLE-BLACK-CAR-HI.GRF,1,1^FS^XZ").getBytes());

 

That only printed the command itself as a string.  We also attempted to use the sendCommand(String) method from the ZebraPrinter class of the Zebra Android SDK, but that returned the same results – printing the command as is on paper.

 

We also used ZebraUtilities to manually set the language to ZPL on Zebra ZQ520, by sending -- ! U1 setvar "device.languages" "ZPL" – command to the printer via the “Open Communication With Printer” tool from the ZebraUtilities application. Unfortunately, that did not change the way the printer interpreted the ZPL command for image printing, as the command kept getting printed as a String. It also did not change the situation when we tried the printImage() method from the GraphicsUtil interface of the Zebra Android SDK.

 

We also tried to use the ZebraUtilities Android app from Google Play Store, and the image print via the app renders the same results.

 

It looks like the printer does not interpret ZPL language for some reason.

 

Could anyone advise as to what could be done in this case? What is missing in the code above, or what should be changed in the steps that are taken before the image can be printed? Firmware version of our ZQ520 is V76.19.13Z.

Manuel Caicedo-...
Hi Anastassia,The behavior,

Hi Anastassia,

The behavior, you described, happens when the printer language is "line_print".

When you tried to set up the language to ZPL, it was not accepted by the printer because the command is case sensitive. In other words, you can try the command like this

! U1 setvar "device.languages" "zpl"

ZPL must be in lower case in order to be accepted by the printer.

The printer ZQ510 by default is set up in "line_print".

For more information about Zebra's API, please follow the link below

Zebra API for Android (build v2.9.2275)

For more information about our recommendations to develop apps with Zebra printers, please, follow the link below

Zebra Technologies - Best Practices in Creating a Printing Application for Zebra Printers

Please, let us know if you were able to set up the language to ZPL. Otherwise, please, reach us at ISV_NALA_Support@zebra.com

Thanks,

MC

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Anonymous (not verified)
Hi Manuel,I am responding to

Hi Manuel,

I am responding to a pretty old thread here :-) I'm with Zebra in Minnesota, and I'm trying to print a sample signature before I plug the code into my app.

I'm doing this (code below), but I get an error that "bitmap is not an Android.Graphics.Bitmap...", when it clearly is. I explicitly set language to ZPL but it doesn't seem to make a difference. If you can spot anything that'd be much appreciated.

Bitmap bitmap = BitmapFactory.DecodeFile (bitmapFile); //, options);

IZebraPrinter printer = ZebraPrinterFactory.Current.GetInstance (PrinterLanguage.ZPL, printerConnection); //this does not set to ZPL

string setLanguage = "! U1 setvar \"device.languages\" \"zpl\"";
printerConnection.Write (GetBytes(setLanguage)); //this DOES set to ZPL

printer.PrintImage(new ZebraImageAndroid (bitmap), 0, 0, bitmap.Width, bitmap.Height, false);

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Anonymous (not verified)
Hi Peter,The last line should

Hi Peter,

The last line should be :

printer.PrintImage(ZebraImageFactory.getImage(bitmap), 0, 0, bitmap.Width, bitmap.Height, false);

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Anonymous (not verified)
After we dug into this

After we dug into this offline, the issue is with the bitmap itself.  Zebra printers do not know how to handle transparency in bitmaps.  Removing the Alpha channel in the file should give a printable image.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Log in to post comments