我正在开发一个需要打印联邦快递运输标签的.NET WinForms应用程序。作为FedEx应用编程接口的一部分,我可以获取打印机的原始标签数据。
我只是不知道如何通过.NET (我使用的是C#)将数据发送到打印机。要清楚的是,数据已经预先格式化成ZPL (斑马打印机语言),我只需要将它发送到打印机,而不是windows搞砸它。
发布于 2008-09-23 19:18:56
C#不支持原始打印,您必须使用win32假脱机程序,如这篇知识库文章How to send raw data to a printer by using Visual C# .NET中所述。
希望这能有所帮助。
-Adam
发布于 2008-09-24 03:38:09
Raw printing helper class from MSDN
发布于 2008-09-23 19:24:11
我想您只是想将ZPL (下面的作业)直接发送到您的打印机。
private void SendPrintJob(string job)
{
TcpClient client = null;
NetworkStream ns = null;
byte[] bytes;
int bytesRead;
IPEndPoint remoteIP;
Socket sock = null;
try
{
remoteIP = new IPEndPoint( IPAddress.Parse(hostName), portNum );
sock = new Socket(AddressFamily.InterNetwork,
SocketType.Stream,
ProtocolType.Tcp);
sock.Connect(remoteIP);
ns = new NetworkStream(sock);
if (ns.DataAvailable)
{
bytes = new byte[client.ReceiveBufferSize];
bytesRead = ns.Read(bytes, 0, bytes.Length);
}
byte[] toSend = Encoding.ASCII.GetBytes(job);
ns.Write(toSend, 0, toSend.Length);
if (ns.DataAvailable)
{
bytes = new byte[client.ReceiveBufferSize];
bytesRead = ns.Read(bytes, 0, bytes.Length);
}
}
finally
{
if( ns != null )
ns.Close();
if( sock != null && sock.Connected )
sock.Close();
if (client != null)
client.Close();
}
}https://stackoverflow.com/questions/123154
复制相似问题