A working example

Sep 19, 2014 at 10:03 AM
First of all, "A quick-start guide to using the APIs" example is outdated. you should update it with the new API.

I downloaded the latest version but its not working on my computer. I used the following peace of code but not a chance. Nothing happens when I run this code. Would you please give me a peace of working code with the latest API?

PrinterSettings p = new PrinterSettings();
p.PrinterName = "ZDesigner GK420d";
p.Darkness = 30;
p.Width = 2034; //for a 203dpi printer head and a 4 inch width label
p.Length = 203
6;

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());
Coordinator
Sep 19, 2014 at 11:36 PM

The example is up to date. If you need help maybe you could give some information on your configuration, like what printer are you using?

Sep 20, 2014 at 6:11 PM
Thanks for your answer.

I meant the example at the following address is outdated. For example there is no Height property over there for PrinterSettings any longer:
https://sharpzebra.codeplex.com/wikipage?title=Two%20Minute%20Quickstart&referringTitle=Home

I am using ZDesigner GK420d printer. I am sure printer is working fine because I can send raw command and print out stuff on the labels. But using SharpZebra library nothing happens when I execute the code I mentioned earlier. I have no idea what is missing.

pleas let me know If you need more specific info.
Coordinator
Sep 20, 2014 at 11:39 PM

Height is current. Are you using the latest version? The git version is out of date.

Sep 22, 2014 at 6:51 AM
That's weird! I just downloaded the latest version (0.91) from codeplex and there is no Height property for PrinterSettings class. I am a bit confused, Am I missing something?
Oct 5, 2014 at 6:49 PM
Hello i think there is no font property in the latest version(0.91) beacuse as @msahra said it gives error when i use TextWrite method like you show in the link below
https://sharpzebra.codeplex.com/wikipage?title=Two%20Minute%20Quickstart&referringTitle=Home

i use like this (without font property) but it prints a blank label. Is there something that i am missing ?
            ...printer settings... 
             List<byte> page = new List<byte>();
            page.AddRange(ZPLCommands.ClearPrinter(ps));
            page.AddRange(__ZPLCommands.TextWrite(10, 150, ElementDrawRotation.NO_ROTATION, 15, "Hello World!")__);

            page.AddRange(ZPLCommands.PrintBuffer(1));
            new SpoolPrinter(ps).Print(page.ToArray());   
thanks.
Coordinator
Oct 5, 2014 at 10:46 PM
If you don't specify the font, it will use the previous font.
What error do you get when you try to set the font with TextWrite?
Can you show your ZebraSettings? Width, height and darkness are usually the culprits for a blank label.
Oct 5, 2014 at 11:03 PM
When I try it like that
ZPLCommands.TextWrite(10, 150, ElementDrawRotation.NO_ROTATION, ZebraFont.STANDARD_NORMAL , 15, "Hello World!");
               
It gives the error below
Error   1   The best overloaded method match for 'Com.SharpZebra.Commands.ZPLCommands.TextWrite(int, int, Com.SharpZebra.ElementDrawRotation, int, string, int)' has some invalid arguments ~\Shipment.cs   224 17   
Dec 17, 2014 at 4:11 PM
Same here. I have installed the drivers for my Zebra P330m Card Printer USB printer. Compiled the dll and added a reference to my asp.net project.
Added the code below

PrinterSettings p = new PrinterSettings();
p.PrinterName = "ZDesigner GK420d";
p.Darkness = 30;
p.Width = 2034; //for a 203dpi printer head and a 4 inch width label
p.Length = 2036;

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());

Data does not even get sent to the printer, though stepping through the code the Boolean is is success?

Also same here again, the .Height variable is not recognised, error being

Com.SharpZebra.Printing.PrinterSettings' does not contain a definition for 'Height' and no extension method 'Height' accepting a first argument of type 'Com.SharpZebra.Printing.PrinterSettings' could be found (are you missing a using directive or an assembly reference?)
Coordinator
Dec 21, 2014 at 4:55 PM
Edited Dec 21, 2014 at 4:56 PM
I just double checked, and sure enough the Height variable is in fact named Length. I'm not sure how or when I changed this. I've updated the tutorials. I'm sorry for the confusion it's caused everyone here.

PaulusMaximus:
Unless your P330m printer is called "ZDesigner GK420d" in your windows printer list, your code won't work. For a spoolprinter you have to supply the actual windows name of the printer for it to work.
Dec 23, 2014 at 10:18 AM
Apologies, I cut and pasted the original code from the example without amending what I actually have in my project. It should have read as:-

p.PrinterName = "Zebra P330m Card Printer USB";

That should work, right?

Also the amount of arguments in the function (as mentioned by unicod) are different than the example code.

The example code says:-
       page.AddRange(ZPLCommands.TextWrite(10, 150, ElementDrawRotation.NO_ROTATION, ZebraFont.STANDARD_NORMAL, 15, "Hello World!"));
This is too many arguments, however I changed the function to :-
        page.AddRange(ZPLCommands.TextWrite(1, 1, Com.SharpZebra.ElementDrawRotation.NO_ROTATION, 2, "Hello World!"));
and there are no errors.

I haven't got the printer to hand but will try again. Thanks