gpt4 book ai didi

c# - Zebra 标签打印机 c# SDK

转载 作者:行者123 更新时间:2023-11-30 16:54:28 25 4
gpt4 key购买 nike

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

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

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

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

最佳答案

我稍后会在找到它时添加源链接,但这是我目前打印到 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。

关于c# - Zebra 标签打印机 c# SDK,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30491748/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com