Printing PNG or GIF dynamically

1,393 views
Skip to first unread message

Ferdinand Joseph

unread,
Oct 1, 2013, 7:54:42 AM10/1/13
to jzebra...@googlegroups.com
Hi,
I am using the jZebra .jar file in my java application. This application needs to print a thumbnail of a person along with his name in the label on a ZM400 thermal printer. Unfortunately, there is no api from Zebra to convert a GIF file to GRF. I was wondering if there is any feature or if I can use jZebra to convert the GIF or PNG to a GRF format, include this in my string of ZPL commands and send it to the printer on the fly ?

any insights would help a  lot.
Thanks
Ferdinand


Tres Finocchiaro

unread,
Oct 1, 2013, 10:35:07 AM10/1/13
to jZebra users
Ferdinand,

Yes, this is currently a supported feature and can be found in the sample.html with the latest version.

Your printer is listed as supporting EPL and ZPL, so depending on which you're using now, one of these methods should work.

Here's a snippet from the TutorialWebApplet wiki page:

// Zebra (EPL):
      document
.jzebra.appendImage("image.png", "EPL");
     
while (!document.jzebra.isDoneAppending()) {} // wait
      document
.jzebra.append("\r\n");          

// Zebra (ZPLII):
      document
.jzebra.appendImage("image.png", "ZPLII");
     
while (!document.jzebra.isDoneAppending()) {} // wait
      document
.jzebra.append("\r\n");  

-Tres

--
--
To unsubscribe from this group, send email to jzebra-users...@googlegroups.com
 
http://code.google.com/p/jzebra
 
---
You received this message because you are subscribed to the Google Groups "jZebra users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jzebra-users...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Ferdinand Joseph

unread,
Oct 4, 2013, 10:15:48 AM10/4/13
to jzebra...@googlegroups.com
Hi Tres,
Thank you for your speedy reply... I was trying to do that using the JAR file in a Java application. 
Would this work.. ? do you have any code snippet to try out perhaps ?
thanks
Ferdinand

Tres Finocchiaro

unread,
Oct 4, 2013, 3:48:20 PM10/4/13
to jZebra users
Ferdinand,

My mistake, I misread your original question.  I see now that you did specify Java.  It is so very rare that I get questions about Java I overlooked it.

Here's how to do it (pseudo-code, not tested):

import java.awt.image.BufferedImage;
import qz.ImageWrapper; 
...
... 
BufferedImage img = ImageIO.read(new File("image.png"));
ImageWrapper iw = new ImageWrapper(img, "ZPLII");
byte[] data = iw.getImageCommand(); 
...

If you want a String version of this, you can always convert the byte array:
String cmds = new String(data); 
...

If you are using EPL, you can just change the second parameter:
ImageWrapper iw = new ImageWrapper(img, "EPL");

Let me know if this works for you.  I can create a demo desktop app to test it too if you are unsuccessful.

-Tres

Ferdinand Joseph

unread,
Oct 6, 2013, 3:18:27 PM10/6/13
to jzebra...@googlegroups.com
Hey Tres,
Thank you so much for your help. I followed your code and I am still struggling with getting the image printed on the ZM400.
I was able to get the image from a URL
                             URL imageURL = new URL(profilePicUrl);
                   // Read this Image
                    BufferedImage img = ImageIO.read(imageURL);
                    // Wrap it to ZPL Format
                    ImageWrapper iw = new ImageWrapper(img, LanguageType.ZPLII);
                    // prefix with GFA
                    byte[] data = iw.getImageCommand();
                    // Convert it to Ascii 
                    String picData = new String(data);
                    System.out.println(picData);

I am able to see this string..
^GFA,312,312,6,000000000000200000000000000008000000022C0300000010BF098008085C3FFFF81442060B75B8D651A526FFC634C00D31B6E52FA3CD3D9AB131F8BEFFE6FC23CE1F7D7F8F0E7A53FB0F81CAC3FAFF4FF2F39F98DBC7F82D8222E6EDFD9F241DA7FF7E7F1F3945670E3F81EF83F3C39FE0F00CEEE0863FBAA3F18FCDF1EF9BEE63CAB9FCE7FB9F60FF3FF3B7BBF86FFB20CDDEF88FFDEE38B7DD60FE77DF3C47723FFFF7E410FF87F3FFF838FBF7733FE6CFE677DFEFE1BCE10E4FE5F005383F047F7FE86E63803EF9F23FFFFDF9C6FC06FFF91DE3BB3FF9FFE2638DBFF070FF39FF47FCCC19D03FB3E7BE0993007FFFEF66FC003C7BFFFFBFFC1F979BFF33FE7049EC1FC39FC0017833CBA3FFFF101D80E6FFFFF9CF3F7F3FFFFF1783FC0FFFFFFFCFF00FFFFF3FFCFF7FFD3FFFFFFFFFC31FFFFFFFFF

But I am not able to see it in the print out.. I am sending the following command to the printer..
 ^XA^XFR:TemplateD.ZPL^FN12^FDSmith, Jeffman^FS^FN11^FDJeffman^FS^FO320,288^GFA,312,312,6,000000000000200000000000000008000000022C0300000010BF098008085C3FFFF81442060B75B8D651A526FFC634C00D31B6E52FA3CD3D9AB131F8BEFFE6FC23CE1F7D7F8F0E7A53FB0F81CAC3FAFF4FF2F39F98DBC7F82D8222E6EDFD9F241DA7FF7E7F1F3945670E3F81EF83F3C39FE0F00CEEE0863FBAA3F18FCDF1EF9BEE63CAB9FCE7FB9F60FF3FF3B7BBF86FFB20CDDEF88FFDEE38B7DD60FE77DF3C47723FFFF7E410FF87F3FFF838FBF7733FE6CFE677DFEFE1BCE10E4FE5F005383F047F7FE86E63803EF9F23FFFFDF9C6FC06FFF91DE3BB3FF9FFE2638DBFF070FF39FF47FCCC19D03FB3E7BE0993007FFFEF66FC003C7BFFFFBFFC1F979BFF33FE7049EC1FC39FC0017833CBA3FFFF101D80E6FFFFF9CF3F7F3FFFFF1783FC0FFFFFFFCFF00FFFFF3FFCFF7FFD3FFFFFFFFFC31FFFFFFFFF^XZ

The printer uses the TemplateD which is a ZPL already stored in the printer.. fills in the values FN11 and FN12.. in addition it should also add the picture which is fed by the URL in profilePic. Unfortunately the names are printed.. but the image is blank. I am not sure what mistake I am doing.. anything wrong with my ZPL commands that I am adding ..?

your speedy help is highly appreciated.
thanks
Ferdinand

Tres Finocchiaro

unread,
Oct 6, 2013, 7:43:40 PM10/6/13
to jZebra users

I don't have much experience with ZPL and don't have a device to test on.

Does anyone on the list have luck printing images using ZPL?

I don't see anything alarming with your code but I've never attempted templates before, and the ZPL image code is not something I've actually seen work, so perhaps someone else can vouch for it.

-Tres

--
Reply all
Reply to author
Forward
0 new messages