首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >斑马标签打印机c# SDK

斑马标签打印机c# SDK
EN

Stack Overflow用户
提问于 2015-05-28 03:43:12
回答 2查看 12.6K关注 0票数 4

我们刚刚从brother label打印机转移到了zebra,brother sdk的c#版看起来很不错,但它做了我想要做的事情。基本上,它为我提供了在设计器中创建标签并将引用名称附加到文本文件、条形码文件等的选项。然而,看着斑马,我似乎找不到一种方法来做到这一点。我不喜欢的事实是,你必须使用缺乏此功能的设计器来设计标签,或者在c#中100%地设计,这会阻止我们的设计师以后重新设计标签,也就是硬编码标签是行不通的。

我一直在寻找由新动力的热敏标签,但它的成本很高,为这个小东西。

有没有我错过的解决方案?大量的谷歌搜索,甚至试图弄清楚如何通过c#将现有的兄弟标签打印到斑马打印机上。这是可能的,因为p-touch可以做到这一点,但我也认为sdk缺乏这一功能,这使得它无论如何都是不可能的。

在查看了brother sdk的更多选项后,我注意到我可以获得bmp格式的标签,这可以方便地打印到斑马标签打印机上吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-05-28 04:05:42

当我找到源链接时,我会添加它,但这是我现在打印到我们的斑马的方式:

代码语言:javascript
复制
[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。

票数 2
EN

Stack Overflow用户

发布于 2015-05-28 03:57:32

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

如果您的斑马是通过网络连接的,最简单的方法/解决方法是使用"NET use lpt1:[ip]zebra /persistent:yes

您可以使用Zebra Designer通过“打印到文件功能”轻松地生成ZPL。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30491748

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档