Sending Raw Data to a Label FedEx Printer

I am working on a .NET WinForms application that should print a FEDEX delivery shortcut. As part of the FedEx api, I can get raw label data for the printer.

I just don’t know how to send this data to the printer through .NET (I use C #). To be clear, the data is already pre-formatted in ZPL (Zebra printer language). I just need to send it to the printer without turning off the window.

+4
source share
6 answers

Since C # does not support raw printing, you will have to use the win32 queue manager as described in this blog post How to send raw data to a printer using Visual C # .NET .

Hope this helps.

-Adam

+10
+2

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

ZPL, Ruby. ZPL .

, , ^XA^PH^XZ . , .

0
0

Zebra , . ZPL. , .

0

All Articles