Sending raw data to FedEx Label printer

微笑、不失礼 提交于 2019-12-18 04:25:06

问题


I'm working on a .NET WinForms app that needs to print a FEDEX shipping label. As part of the FedEx api, I can get raw label data for the printer.

I just don't know how to send that data to the printer through .NET (I'm using C#). To be clear, the data is already pre formatted into ZPL (Zebra printer language) I just need to send it to the printer without windows mucking it up.


回答1:


C# doesn't support raw printing, you'll have to use the win32 spooler, as detailed in this KB article How to send raw data to a printer by using Visual C# .NET.

Hope this helps.

-Adam




回答2:


Raw printing helper class from MSDN




回答3:


I think you just want to send the ZPL (job below) directly to your printer.

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();
    }
}



回答4:


A little late, but you can use this CodePlex Project for easy ZPL printing http://sharpzebra.codeplex.com/




回答5:


Zebra printers don't use a spooler, it isn't raw printing. It's a markup called ZPL. It's text based, not binary.




回答6:


I've been working with a printer and ZPL for a while now, but with a Ruby app. Sending the ZPL out to the printer via socket works fine.

To check that it works, I often telnet to the printer and type ^XA^PH^XZ to feed a single label. Hope that helps.



来源:https://stackoverflow.com/questions/123154/sending-raw-data-to-fedex-label-printer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!