4
votes

We just moved from brother label printers to zebra and the brother sdk for c# is kind of meh but it did what I wanted it to do. Basically it gave me the option to create a label in the designer and attach reference names to the text files, barcode files etc. However looking at zebra I can't seem to find a way to do that. I don't like the fact that you'd have to design the labels using their designer which lacks this function or do it 100% in c# which prevents our designer from re-designing the label later down the road, aka hardcoding labels is a no go.

I've been looking at thermallabel by neodynamic but it costs way to much for this little thing.

Is there a solution out there I've missed? tons and tons of googling and even trying to figure out how to print the existing brother labels through c# to the zebra printer. This is possible (maybe) since p-touch can do it but I also think the sdk lacks this function which makes it impossible anyways.

After looking over the brother sdk for some more options I noticed I can get the label as a bmp, could that be easily printed to the zebra label printer?

2
While most label printer manufacturers seem to like to have their own printing language, all of them also works as a normal printer. That's the way I went with the printers we deliver with our equipment. You'll have to generate all the content yourself, but it gives you alot of flexibility and doesn't tie you to a single manufacturers crappy label software.Chris
You can save your ZPL code to a simple text file and then use a shell command to move it on LPT1.Seb
I think he's saying their labels aren't in ZPL, but whatever Brother uses, is that a correct assumption Makkesk8?JWiley
well both yes and no, we are currently using brother labels since we haven't got the zebra sdk setup for our c# project. We are flexible so we can change over to zebra labels without any issues.Makkesk8

2 Answers

2
votes

I'll add the source link later when I find it, but this is how I print to our Zebra as of now:

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
        public class DOCINFOA
        {
            [MarshalAs(UnmanagedType.LPStr)]
            public string pDocName;
            [MarshalAs(UnmanagedType.LPStr)]
            public string pOutputFile;
            [MarshalAs(UnmanagedType.LPStr)]
            public string pDataType;
        }
        [DllImport("winspool.Drv", EntryPoint = "OpenPrinterA", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
        public static extern bool OpenPrinter([MarshalAs(UnmanagedType.LPStr)] string szPrinter, out IntPtr hPrinter, IntPtr pd);

        [DllImport("winspool.Drv", EntryPoint = "ClosePrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
        public static extern bool ClosePrinter(IntPtr hPrinter);

        [DllImport("winspool.Drv", EntryPoint = "StartDocPrinterA", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
        public static extern bool StartDocPrinter(IntPtr hPrinter, Int32 level, [In, MarshalAs(UnmanagedType.LPStruct)] DOCINFOA di);

        [DllImport("winspool.Drv", EntryPoint = "EndDocPrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
        public static extern bool EndDocPrinter(IntPtr hPrinter);

        [DllImport("winspool.Drv", EntryPoint = "StartPagePrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
        public static extern bool StartPagePrinter(IntPtr hPrinter);

        [DllImport("winspool.Drv", EntryPoint = "EndPagePrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
        public static extern bool EndPagePrinter(IntPtr hPrinter);

        [DllImport("winspool.Drv", EntryPoint = "WritePrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
        public static extern bool WritePrinter(IntPtr hPrinter, IntPtr pBytes, Int32 dwCount, out Int32 dwWritten);


public static bool SendStringToPrinter(String printerName, String dataString)
        {
            int dwCount = (dataString.Length + 1) * Marshal.SystemMaxDBCSCharSize;

            // Assume that the printer is expecting ANSI text, and then convert
            // the string to ANSI text.
            IntPtr pBytes = Marshal.StringToCoTaskMemAnsi(dataString);
            // Send the converted ANSI string to the printer.
            SendPBytesToPrinter(printerName, pBytes, dwCount);
            Marshal.FreeCoTaskMem(pBytes);
            return true;
        }


        public static bool SendPBytesToPrinter(String szPrinterName, IntPtr pBytes, Int32 dwCount)
        {
            Int32 dwError = 0, dwWritten = 0;
            IntPtr hPrinter = new IntPtr(0);
            DOCINFOA di = new DOCINFOA();
            bool bSuccess = false; // Assume failure unless you specifically succeed.
            di.pDocName = "My C#.NET RAW Document";
            di.pDataType = "RAW";

            // Open the printer.
            if (OpenPrinter(szPrinterName.Normalize(), out hPrinter, IntPtr.Zero))
            {
                // Start a document.
                if (StartDocPrinter(hPrinter, 1, di))
                {
                    // Start a page.
                    if (StartPagePrinter(hPrinter))
                    {
                        // Write your bytes.
                        bSuccess = WritePrinter(hPrinter, pBytes, dwCount, out dwWritten);
                        EndPagePrinter(hPrinter);
                    }
                    EndDocPrinter(hPrinter);
                }
                ClosePrinter(hPrinter);
            }

            if (bSuccess == false)
            {
                dwError = Marshal.GetLastWin32Error();
                //TODO: log error code
            }
            return bSuccess;
        }

Where dataString is the ZPL interpreted by the printer.

0
votes

You can save your ZPL code to a simple text file and then use a shell command to move it on LPT1.

If your zebra is plugged via network, the simplest way/workaround is to use "NET USE lpt1: \[ip][zebra] /persistent:yes

You can use Zebra Designer to easily generate ZPL for you using the "print to file function"