Using the ZPL Patch, Graphics

Nov 21, 2011 at 8:03 PM

Can someone help me out with an example to use Graphics ZPLCommands, the functions are different from the documentation and am having trouble trying to figure out where to start just printing a simple graphic.

Thanks.

Coordinator
Nov 21, 2011 at 8:17 PM
Edited Nov 21, 2011 at 8:23 PM

Uploading an image to the printer:

List<byte> res = new List<byte>();
res.AddRange(ZPLCommands.ClearPrinter(p.Settings));
res.AddRange(ZPLCommands.GraphicDelete('E', "SAMPLE"));
res.AddRange(ZPLCommands.ClearPrinter(p.Settings));
res.AddRange(ZPLCommands.GraphicStore(new Bitmap(@"C:\Sample.bmp"), 'E', "SAMPLE"));
p.Print(res.ToArray());

 

Printing the uploaded image:

List<byte> res = new List<byte>();
res.AddRange(ZPLCommands.ClearPrinter(p.Settings));
res.AddRange(ZPLCommands.GraphicWrite(20, 5, "SAMPLE", 'E'));
p.Print(res.ToArray());

Nov 21, 2011 at 8:26 PM

Wow that was fast! Thanks so much that did the trick!

Jul 26, 2012 at 1:40 AM

Hello,

First, thanks you for uploading this useful library.

I'm trying to print an image that I created dynamically (an image that is not stored to disk) and I used the code mentioned above with the addition of the print buffer command. However, my problem is that I always get empty labels.

Any ideas of how to fix this? I tried the simple clear printer command, the one with the ^XA only, but with no difference in the resulting labels.

Appreciate your help,

Iman

Coordinator
Jul 26, 2012 at 2:53 AM

Hi Iman,

I assume you can get text output with the printer?  It's just the image that fails to print?  What about text plus your image - does just the text show up or nothing?

If the problem is just with the image, it's likely due to the image format.  The printers work best with a 1-bit image source - black and white.  My Graphicstore routine actually only looks at the Red component of the bitmap, and only prints the pixel if it's value is higher than 128.

 

Although I would suggest the above method is bad for using with dynamic images - the printers use flash memory to store data, everytime you print using the above method, you write to the flash, and while it takes a ton of writes, the flash will go bad after a while (100k writes maybe?)  The above method should really only be used to store static images that are used repeatedly.

IIRC, there are ZPL commands to write graphics directly to the buffer (which doesn't degrade).  Unfortunately I haven't added a routine for that, as it wasn't something I needed.  I don't think it would take much to convert my graphicstore routine to use the command to write the image to the buffer, I will actually be working with the library again tomorrow, I'll take a quick look at it then...

Thanks,

Rob

Jul 26, 2012 at 10:29 AM
Edited Jul 26, 2012 at 11:00 AM
Thanks for your reply Rob,
I will try to print plain text as soon as I reach the zebra printer again (I don't have it at hand all the time). I will also try to convert my image into black and white before printing it and see what will be the output.
Kindly update me if you found anything that might help with my issue. I would need to print a bunch of images at once (created dynamically), its not only one image.
Thanks again,
Appreciate your help,
Iman
Jul 26, 2012 at 4:44 PM

Hello Rob,

I just tried to print plain text, but I'm also getting empty labels!

Here is my code:

List<byte> res = new List<byte>();

res.AddRange(ZPLCommands.ClearPrinter(zebraPrinterSettings));
res.AddRange(ZPLCommands.TextWrite(3, 3, Com.SharpZebra.ElementDrawRotation.NO_ROTATION, Com.SharpZebra.ZebraFont.STANDARD_NORMAL, 10, 30, "Hello"));
res.AddRange(ZPLCommands.PrintBuffer(1));
myPrinter.Print(res.ToArray());

Any ideas of what is causing this error?

Thanks,

Iman

Coordinator
Jul 26, 2012 at 5:33 PM
Edited Jul 26, 2012 at 5:38 PM

I think you should be using

res.AddRange(ZPLCommand.ClearPrinter(myPrinter.Settings));

for the clearprinter command..

Also, try setting myPrinter.Settings.Darkness = 23;

good values are between 20-30 I think, depending on printer and thermal transfer vs direct thermal

Coordinator
Jul 26, 2012 at 6:19 PM

I've looked into the Flash memory issue.  I was partially wrong - there's no command to upload graphics to the buffer.  You should upload your dynamic images to the RAM drive on the printer (I think on most zebra printers you use 'R' instead of 'E' for GraphicStore and GraphicWrite).  Everything else will stay the same.

Jul 29, 2012 at 12:13 PM

Hello Rob,

I tried "myPrinter.Settings" for the clearprinter command and I also set the darkness to 23 and still no text is being printed at all. I just get empty labels.

My printer is Zebra Stripe 400, I'm starting to think that maybe the printer is old and doesn't understand the commands. I even downloaded your old SharpZebra library (unmodified version that doesn't support graphics) and tried the sample windows application you provided to print labels and yet nothing is being printed, not even empty labels!

Appreciate your help a lot,

Iman

Coordinator
Jul 29, 2012 at 6:50 PM

Does the printer print anything if you use the windows print driver to print something from notepad?  The printer supports ZPL2 so it works with the library for sure...

Aug 2, 2012 at 10:58 AM

Finally some good news. My printer is now printing text labels. The problem was with the driver installed for my printer, when re-installed the appropriate driver from the internet, the labels weren't empty anymore. I was also able to print an image, but it was shrinked to the corner of the label.

Anyways, I will try other ZPL graphics commands and see what will I get.

Thanks a lot,

Iman

May 5, 2014 at 3:55 PM
Can someone help me I getting Black spot labels! like in picture
Image

this my code
private void button2_Click(object sender, EventArgs e)
    {
        PrinterSettings p = new PrinterSettings();
        p.PrinterName = "Zebra  105SL (200dpi)";
        p.Darkness = 30;
        List<byte> res = new List<byte>();
        res.AddRange(ZPLCommands.ClearPrinter(p));
        res.AddRange(ZPLCommands.GraphicDelete('E', "SAMPLE"));
        res.AddRange(ZPLCommands.ClearPrinter(p));
        res.AddRange(ZPLCommands.GraphicStore(new Bitmap(@"E:\expv2\SAMPLE.png"), 'E', "SAMPLE"));
        res.AddRange(ZPLCommands.PrintBuffer(1));
        new SpoolPrinter(p).Print(res.ToArray());

        List<byte> ress = new List<byte>();
        ress.AddRange(ZPLCommands.ClearPrinter(p));
        ress.AddRange(ZPLCommands.GraphicWrite(90, 141, "SAMPLE", 'E'));
        ress.AddRange(ZPLCommands.PrintBuffer(1));
        new SpoolPrinter(p).Print(ress.ToArray());
        ress.AddRange(ZPLCommands.PrintBuffer(1));
        new SpoolPrinter(p).Print(ress.ToArray());


    }
Coordinator
May 5, 2014 at 4:04 PM
PNG files aren't supported. Try converting it to a BMP first.
May 6, 2014 at 4:31 PM
Thanks for the reply
i try to convert to BMP Nothing has changed
I Print Test page ,It turns out that the black spots from the printer, Means the printer print with Black spot put its work fine windows logo printed

so when I use this code
        PrinterSettings p = new PrinterSettings();
        p.PrinterName = "Zebra  105SL (200dpi)";
        p.Darkness = 30;
        List<byte> res = new List<byte>();
        res.AddRange(ZPLCommands.ClearPrinter(p));
        res.AddRange(ZPLCommands.TextWrite(50, 50, ElementDrawRotation.NO_ROTATION, ZebraFont.STANDARD_NORMAL, 50, 50, "Hello"));
        res.AddRange(ZPLCommands.PrintBuffer(1));
        new SpoolPrinter(p).Print(res.ToArray());
only Paper comes out no print
Coordinator
May 6, 2014 at 4:53 PM
Edited May 6, 2014 at 4:54 PM
It looks fine, and since the printer is printing, you are connecting and sending commands to it.

Try specifying the label width.
p.Darkness = 30;
p.Width = 200*4; //for your 200dpi printer and a 4 inch width label 
p.Length = 200*6;
List<byte> res = new List<byte();
...
May 6, 2014 at 6:30 PM
that's was it ..
   Appreciate your help 

     Thanks a lot,