Zebra 标签打印机 c# SDK

Zebra label printer c# SDK

我们刚刚从 brother label printers 转移到 zebra,brother sdk for c# 有点无聊,但它做了我想做的事。基本上它让我可以选择在设计器中创建标签并将参考名称附加到文本文件、条形码文件等。但是看着 zebra 我似乎无法找到一种方法来做到这一点。我不喜欢这样一个事实,即您必须使用缺少此功能的设计器来设计标签,或者 100% 在 c# 中进行设计,这会阻止我们的设计器以后重新设计标签,也就是硬编码标签不行。

我一直在研究 neodynamic 的 thermallabel,但是这个小东西要花很多钱。

是否有我错过的解决方案?大量的谷歌搜索,甚至试图弄清楚如何通过 C# 将现有的兄弟标签打印到斑马打印机。这是可能的(也许),因为 p-touch 可以做到,但我也认为 sdk 缺少此功能,因此无论如何都不可能。

在查看兄弟 sdk 的更多选项后,我注意到我可以获得 bmp 格式的标签,可以轻松打印到 zebra 标签打印机吗?

您可以将 ZPL 代码保存到一个简单的文本文件中,然后使用 shell 命令将其移动到 LPT1。

如果您的 zebra 是通过网络插入的,最简单的 way/workaround 是使用“NET USE lpt1: \[ip][zebra] /persistent:yes

您可以使用 Zebra Designer 使用 "print to file function"

轻松地为您生成 ZPL

我稍后会在找到来源后添加 link,但这是我目前打印到 Zebra 的方式:

[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;
        }

其中 dataString 是打印机解释的 ZPL。