For me with a PNG file (no transparency) it is working as follows, once you did the read to end:
Calling the method to get ZPL:
var zpl = GetImgZpl(text);
Console.WriteLine(zpl);
The method:
private string GetImgZpl(string imgTxt)
{
return "^XA"
+ "~" + imgTxt
+ "^FO70,70^IME:IMAGE.PNG^FS"
+ "^IDE:IMAGE.PNG"
+ "^XZ";
}
Generated ZPL:
^XA
~ DYE:IMAGE p p 2764 :B64:iVBORw0KGgoAA (lots of characters...) LzRYWmUgMAAAAASUVORK5CYII=:e11c
^FO70,70
^IME:IMAGE.PNG
^FS
^IDE:IMAGE.PNG
^XZ
This ZPL is sent to the printer and works fine. There are some escaped characters in the formatting above, but the point is that I just get the command as it is returned by PrinterUtil method without any additional processing. The ZPL loads the image in the printer, prints it, then delete from memory (E:).
You wouldn't need to do any of the conversion yourself. Just use the printer.printImage() or printer.storeImage() API's. They take PNG, JPG, and BMP file formats.
Fs = New IO.FileStream("C:\Zebra\ZPL.txt", IO.FileMode.Create)
Ms.WriteTo(Fs)
I tried to put the result of the ZPL.txt file after the ZPL command ^GFA ....but I don't know how to set the three parameters of the ^GF command ....and ....in any case the image printed is not the same as the source jpg.
Hi Daniel, You can use the storeImage() command before sending the zpl and then use the ^FO in combination with the ^IM command to modify the location in your ZPL:
^XA...
^FO10,608^IME:IMAGE.PNG^FS
...^XZ
X and Y coordinates are generally for the top left corner of the image.
Or you can use the printImage() inside format to place it.
Thanks a lot for all this information, very useful.
One question, once you store and print the image, is there a function to remove it from the printer's memory (without resetting the whole printer configuration)? I can't find a printer.DeleteImage() function...
Hi Tim, Sorry this is coming to you so late, but it might help others who need it. The Zebra .Net SDK has a ConvertGraphic() function to convert an image into a B64 encoded PNG image. You can use this without ever opening the connection to a printer. It does add a ZPL download header, but you can remove it by searching for the string ":B64:" and removing everything before that. The filePathOnPrinter must have the PNG extension to convert to a B64 image.
Thank you very much I have worked!
Just one last question, how do I get it into zpl?
What is the ZPL command to display it there ....
Thank you!!!
Points: 0
You voted ‘up’
Hello,
For me with a PNG file (no transparency) it is working as follows, once you did the read to end:
Calling the method to get ZPL:
The method:
Generated ZPL:
This ZPL is sent to the printer and works fine. There are some escaped characters in the formatting above, but the point is that I just get the command as it is returned by PrinterUtil method without any additional processing. The ZPL loads the image in the printer, prints it, then delete from memory (E:).
Good luck,
Diego
Points: 0
You voted ‘up’
Hi Daniel,
You wouldn't need to do any of the conversion yourself. Just use the printer.printImage() or printer.storeImage() API's. They take PNG, JPG, and BMP file formats.
Link-OS SDK - Zebra Technologies Techdocs - look at the GraphicsUtil class for some sample code.
Points: 1
You voted ‘up’
Hello Robin,
Is there a B64 algorithm in an SDK for the .NET Framework? I require it for some software I am developing.
Thanks!
-Tim
Points: 0
You voted ‘up’
Hi Robin.
I'm trying to have a ZPL code from a JPG image ....but the result of the ConvertGraphic funciton is not correctly printed by our Zebra ZT230.
These are the few code lines (Vb.Net - I wrote the ZPL in a file):
Dim Fs As System.IO.FileStream
Dim Ms As New System.IO.MemoryStream
Dim Im As Sdk.Graphics.ZebraImageI
Im = ZebraImageFactory.GetImage("C:\Zebra\150_00_00_02.jpg")
Sdk.Printer.PrinterUtil.ConvertGraphic("c:\Zebra\IMAGE.PNG", Im, 20, 20, Ms)
Fs = New IO.FileStream("C:\Zebra\ZPL.txt", IO.FileMode.Create)
Ms.WriteTo(Fs)
I tried to put the result of the ZPL.txt file after the ZPL command ^GFA ....but I don't know how to set the three parameters of the ^GF command ....and ....in any case the image printed is not the same as the source jpg.
Where I go wrong ?
Thank you in advance !
Points: 0
You voted ‘up’
Hello Andrea,
Not sure if this helps with your GF command issue, but to get the ZPL you need to reset the memory stream position to 0 as follows (in C#):
Hope this helps!
Cheers,
Diego
Points: 0
You voted ‘up’
Thank you Diego for your help !!
The issue is NOT the stream reading .....but the value of the string that the ReadToEnd returns !!
If I put the result in a ZPL viewer it doesn't show me the original picture.
The ZPL viewer doesn't give me an error....simply shows a kind of "qr-code picture".
Maybe the issue is because of the ":B64:" starting string (instead of Z64).
Regards
Points: 0
You voted ‘up’
Hi Daniel, You can use the storeImage() command before sending the zpl and then use the ^FO in combination with the ^IM command to modify the location in your ZPL:
^XA...
^FO10,608^IME:IMAGE.PNG^FS
...^XZ
X and Y coordinates are generally for the top left corner of the image.
Or you can use the printImage() inside format to place it.
String zplStart = "^XA...";
String zplEnd = "...^XZ";
printer.getConnection.write(zplStart
.getBytes()
);printer.printImage("myImage.png", 10, 608, 0, 0, true);
printer.getConnection.write(zplEnd
.getBytes()
);I can't give you specifics for the X and Y locations because I don't know how big your receipt is, or exactly how far down the page it is.
Points: 1
You voted ‘up’
Hello Diego.
I followed your advice ...and I send you the file with the ZPL commands.
If you send to a printer you will don't have any image.
Thank you in advance
Points: 0
You voted ‘up’
Thank you very much Robin, you have helped me a lot!
Points: 0
You voted ‘up’
Hello Robin,
Is there a B64 algorithm in an SDK for the .NET Framework? I require it for some software I am developing.
Thanks!
-Tim
Points: 0
You voted ‘up’
Hello Robin,
Thanks a lot for all this information, very useful.
One question, once you store and print the image, is there a function to remove it from the printer's memory (without resetting the whole printer configuration)? I can't find a printer.DeleteImage() function...
Thank you,
Diego
Points: 0
You voted ‘up’
Hi Tim, Sorry this is coming to you so late, but it might help others who need it. The Zebra .Net SDK has a ConvertGraphic() function to convert an image into a B64 encoded PNG image. You can use this without ever opening the connection to a printer. It does add a ZPL download header, but you can remove it by searching for the string ":B64:" and removing everything before that. The filePathOnPrinter must have the PNG extension to convert to a B64 image.
There are also likely 3rd party libraries to do this.
Points: 0
You voted ‘up’