locked
Zebra Printers - Printing Images RRS feed

  • Question

  • User260742 posted

    Has anyone got working code specifically for the Zebra iMZ series printers. I can print everything to the old MZ series printers (in android, iOS is not supported with these), but the iMZ printers don't seem to print any images at all which is a big problem for us. I know its not an issue with the printer itself as I've seen it print images through a native android app just fine but can't find a way around this - for reference, I'm trying to use the IZebraPrinter.PrintImage method

    Alternatively, has anyone got any other BT printers working within Xamarin and would be able to suggest them to look at? Thanks

    Tuesday, April 25, 2017 8:57 AM

Answers

  • User260742 posted

    I received an official answer from Zebra today (finally) - the reason it wasn't printing images on the iMZ printer and it was on the MZ printers was because I wasn't specifying the PrinterLanguage when creating the connection to the printer:

    printer = ZebraPrinterFactory.GetInstance(printerConnection);
    becomes
    printer = ZebraPrinterFactory.GetInstance(PrinterLanguage.Cpcl, printerConnection);
    

    "The reason behind this being that in the SDK, when an IZebraPrinter is created, it assumes the print language. For non-Link-OS printers (like the MZ), it assumes CPCL and for Link-OS Printers (like the iMZ) it assumes ZPL. The reason the images weren't printing on the iMZ is because the PrintImage was sending the image in ZPL. The printer wasn't able to switch back and forth between the languages."

    I have tested this out and can confirm this has fixed the issue.

    What they didn't explain was why this behaviour was different between using the LinkOS nuget package when using Xamarin vs using the ZSDK.jar file when creating a native android app in Java (as my old code in Java doesn't specify the printerlanguage and works just fine on the iMZ).

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, June 22, 2017 7:02 AM

All replies

  • User2148 posted

    What do you use to print? the Zebra SDK? or directly sending commands to bluetooth socket?

    Tuesday, April 25, 2017 9:05 AM
  • User260742 posted

    I'm using the Zebra SDK to do this - creating an Insecure Bluetooth connection to the printer, creating the IZebraPrinter instance and then sending commands to it like that. Using the old MZ series printers, everything works, but on the iMZ series printers it doesn't print any images.

    An example piece of our code is :

     BitmapFactory.Options op = new BitmapFactory.Options();
     op.InPreferredConfig = Bitmap.Config.Argb8888;
     Bitmap sigImage = BitmapFactory.DecodeFile(sigFilePath, op);
     sigImage = getResizedBitmap(sigImage, 100, (pageWidth / 3) * 2);
     printer.PrintImage(new ZebraImageAndroid(sigImage), pageWidth / 6, sectionCurrentHeight, (pageWidth / 3) * 2, 100, true);
    
    Tuesday, April 25, 2017 9:32 AM
  • User2148 posted

    Sorry never use emdk to print. Have you tried to open a Bluetooth Socket and sends row data to the printer? which language use Zebra? zpl? esc/p?

    Tuesday, April 25, 2017 10:38 AM
  • User260742 posted

    I did originally look at doing that and I could get text to print OK, but I couldn't get the PCX command to work at all with my bitmaps - believing the issue to be the fact that I need the images in PCX format I spent a lot of time trying to find some code that would convert a bitmap into PCX format and the only thing I found was ImageMagick and I couldn't quite get that working for some reason, so I gave up thinking that the SDK would just make things a whole lot easier.

    Tuesday, April 25, 2017 11:52 AM
  • User260742 posted

    Forgot to mention - we're using CPCL to print.

    Tuesday, April 25, 2017 11:53 AM
  • User2148 posted

    Understand. I think it's a emdk problem... there is not a sample in emdk you can use for test?

    Tuesday, April 25, 2017 11:53 AM
  • User2148 posted

    so you are using a language.... I don't know.... usually I open a BluetoothSocket and send raw data. It works with text but I don't remeber if I have ever used an Image...

    Tuesday, April 25, 2017 11:55 AM
  • User260742 posted

    Well I'm using the Link-OS SDK to create the printer instance and effectively you can send it commands (in CPCL) to do the printing which is what I'm doing. But when it comes to images - I can't get the PCX command working and the inbuilt printImage method of the SDK doesn't work. The demo for the Link-OS SDK doesn't include a demo for printing images unfortunately.

    Tuesday, April 25, 2017 12:14 PM
  • User2148 posted

    https://zebra.com/content/dam/zebra/manuals/en-us/printer/cpcl-pm-en.pdf

    at page 95 there is PCX commands. I think you should try sending raw command

    Tuesday, April 25, 2017 1:25 PM
  • User260742 posted

    I tried to go down that route before but it specifically says that the image being sent needs to be in PCX format and this is where I got stuck before - I couldn't find anything to help me convert the bitmaps on the device to PCX format.

    Tuesday, April 25, 2017 1:43 PM
  • User2148 posted

    Do you have these images in the device or do you receive bitmaps from web?

    Tuesday, April 25, 2017 1:44 PM
  • User260742 posted

    They are on the device - I'm using the SignaturePad package to save a signature to a png file which is stored temporarily on the device. I'm then using a BitmapFactory to decode it into a Bitmap object.

    Tuesday, April 25, 2017 1:56 PM
  • User2148 posted

    and you can't convert from bitmap to pcx...

    Tuesday, April 25, 2017 2:26 PM
  • User260742 posted

    I haven't found a way on how to do that - but if anyone has code to do this - I'd be more than happy to go down this route.

    Friday, May 5, 2017 10:04 AM
  • User260742 posted

    Just as an update on this - I realised you could use the LinkOS SDK to store an image on the printer as a PCX file but unfortunately using the PCX command, the same result happens - works on the old MZ series we have - nothing prints out on the iMZ.

    I stripped all the code down so that all I was doing was a printer.PrintImage(..) call and it did print an image on the iMZ - but this is no use as it fed a ton of paper and then printed the image (upside down). The problem seems to be when you send any kind of CPCL to the printer along with printing an image, then it just refuses to print any of the images.

    Gonna have to cut my losses with this - it looks like there is a bug in their Xamarin implementation when printing images via the iMZ series - they've stopped responding to my messages about a month ago so I can't actually verify that - but the fact that it works perfectly via Xamarin on the MZ printer and the iMZ printer works perfectly when running from a native android app seems to confirm that.

    Tuesday, May 9, 2017 11:06 AM
  • User301650 posted

    For anyone here i have a solution for Xamarin.Android, i use as a guide this thread https://developer.zebra.com/thread/34489

    I attach a small project and this is the code i use to print an screenshot.

    Basically this code configure the printer in zpl lenguaje.

    IZebraPrinter printer = ZebraPrinterFactory.Current.GetInstance(PrinterLanguage.ZPL, connection);
    string setLanguage = "\r\n! U1 setvar \"device.languages\" \"zpl\"\r\n";
    byte[] response1 = printer.Connection.SendAndWaitForResponse(Encoding.ASCII.GetBytes(setLanguage), 500, 500);
    

    Save the image bitmap in the printer and send a zpl command to print the saved image, its very important to configure the printer to zpl languaje or you gonna see the image printing as a hexadecimal

    Here is the complete code :D

    Zebra.Sdk.Comm.BluetoothConnectionInsecure thePrinterConn = new Zebra.Sdk.Comm.BluetoothConnectionInsecure(discoveredPrinter.Address);
    //thePrinterConn.Open();
    
    IConnection connection = ConnectionBuilder.Current.Build(thePrinterConn.MACAddress);
    connection.Open();
    
    string setLanguage = "\r\n! U1 setvar \"device.languages\" \"zpl\"\r\n";
    string zpl = "^XA^FO0,0^XGR:IMAGE.GRF^XZ";
    
    IZebraPrinter printer = ZebraPrinterFactory.Current.GetInstance(PrinterLanguage.ZPL, connection);
    
    // Toma pantallazo del celular la guarda en un Bitmap y lo manda a imprimir
    var view = this.Window.DecorView;
    view.DrawingCacheEnabled = true;
    
    Bitmap bitmap = view.GetDrawingCache(true);
    
    byte[] response1 = printer.Connection.SendAndWaitForResponse(Encoding.ASCII.GetBytes(setLanguage), 500, 500);
    printer.StoreImage("R:IMAGE.GRF", bitmap, 500, 800);
    byte[] response2 = printer.Connection.SendAndWaitForResponse(Encoding.ASCII.GetBytes(zpl), 500, 500);
    
    string response1string = Encoding.ASCII.GetString(response1);
    string response2string = Encoding.ASCII.GetString(response2);
    

    Wednesday, June 21, 2017 2:08 PM
  • User260742 posted

    I received an official answer from Zebra today (finally) - the reason it wasn't printing images on the iMZ printer and it was on the MZ printers was because I wasn't specifying the PrinterLanguage when creating the connection to the printer:

    printer = ZebraPrinterFactory.GetInstance(printerConnection);
    becomes
    printer = ZebraPrinterFactory.GetInstance(PrinterLanguage.Cpcl, printerConnection);
    

    "The reason behind this being that in the SDK, when an IZebraPrinter is created, it assumes the print language. For non-Link-OS printers (like the MZ), it assumes CPCL and for Link-OS Printers (like the iMZ) it assumes ZPL. The reason the images weren't printing on the iMZ is because the PrintImage was sending the image in ZPL. The printer wasn't able to switch back and forth between the languages."

    I have tested this out and can confirm this has fixed the issue.

    What they didn't explain was why this behaviour was different between using the LinkOS nuget package when using Xamarin vs using the ZSDK.jar file when creating a native android app in Java (as my old code in Java doesn't specify the printerlanguage and works just fine on the iMZ).

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, June 22, 2017 7:02 AM