How to send EPL2 command to a Zebra LP2844 printer via USB using C#

Mahlye.Sol picture Mahlye.Sol · Aug 8, 2015 · Viewed 7.5k times · Source

I am required to print labels and bar codes on zebra label printer using C#. I have never used them before but read and tried to figure out a way to do that. And I have come across this code from http://support.microsoft.com/kb/322091, but it didn't work. From my trials I can see that I was able to send the data to the printer but it doesn't respond and print. I am using buttons to send the command to the printer just like in the kb article.

private void  ConnectButton_Click(object sender, EventArgs e)
{
    // Allow the user to select a printer.
    string s =  "B26,26,0,UA0,2,2,152,B,\"{0}\"";
    PrintDialog pd =  new PrintDialog();
    pd.PrinterSettings = new PrinterSettings();
    if (DialogResult.OK == pd.ShowDialog(this))
    {
       // Send a printer-specific to the printer.
       RawPrintrHelper.SendStringToPrinter(pd.PrinterSettings.PrinterName,s);
       MessageBox.Show("Data sent to printer.");
    }
}

Answer

Christian Specht picture Christian Specht · Aug 27, 2015

The following two blog posts written by Nicholas Piasecki are an invaluable resource for everybody trying to print to Zebra printers from .NET:

(his website seems to be dead right now, so the links are going to the Wayback Machine)

I've been working with Zebra printers and EPL for more than 10 years, about 6 of them with .NET.
When I started with Zebra/EPL and .NET, those two blog posts were all I needed to get it to work.


Concerning this:

And I have come across this code from http://support.microsoft.com/kb/322091, but it didn't work. From my trials I can see that I was able to send the data to the printer but it doesn't respond and print.

There's a bug in the code in that article, the solution is explained at the bottom of the first blog post that I linked.