Click or drag to resize

FormatUtil Interface

Defines functions used for interacting with printer formats.

Namespace:  Zebra.Sdk.Printer
Assembly:  SdkApi_Core (in SdkApi_Core.dll) Version: 2.14.1869
Syntax
public interface FormatUtil

The FormatUtil type exposes the following members.

Methods
Examples
using System;
using System.Collections.Generic;
using Zebra.Sdk.Comm;
using Zebra.Sdk.Printer;

public class FormatUtilExample {

    public static void Main(string[] args) {
        try {
            new FormatUtilExample().Example1();
            new FormatUtilExample().Example2();
            new FormatUtilExample().Example3();
        } catch (ConnectionException e) {
            Console.WriteLine(e.ToString());
        }
    }

    /// Print a stored format with the given variables. This ZPL will store a format on a printer, for use with example1.
    /// 
    /// ^XA
    /// ^DFE:FORMAT1.ZPL
    /// ^FS
    /// ^FT26,243^A0N,56,55^FH\^FN12"First Name"^FS
    /// ^FT26,296^A0N,56,55^FH\^FN11"Last Name"^FS
    /// ^FT258,73^A0N,39,38^FH\^FDVisitor^FS
    /// ^BY2,4^FT403,376^B7N,4,0,2,2,N^FH^FDSerial Number^FS
    /// ^FO5,17^GB601,379,8^FS
    /// ^XZ
    private void Example1() {
        Connection connection = new TcpConnection("192.168.1.32", TcpConnection.DEFAULT_ZPL_TCP_PORT);
        try {
            connection.Open();
            ZebraPrinter printer = ZebraPrinterFactory.GetInstance(connection);

            Dictionary<int, string> vars = new Dictionary<int, string> {
                { 12, "John" },
                { 11, "Smith" }
            };

            printer.PrintStoredFormat("E:FORMAT1.ZPL", vars);
        } catch (ConnectionException e) {
            Console.WriteLine(e.ToString());
        } catch (ZebraPrinterLanguageUnknownException e) {
            Console.WriteLine(e.ToString());
        } finally {
            connection.Close();
        }
    }

    /// Print a stored format with the given variables. This ZPL will store a format on the Link-OS&#0153; printer,
    /// for use with Example2.
    /// 
    /// ^XA
    /// ^DFE:FORMAT2.ZPL
    /// ^FS
    /// ^FT26,243^A0N,56,55^FH\^FN12"First Name"^FS
    /// ^FT26,296^A0N,56,55^FH\^FN11"Last Name"^FS
    /// ^FT258,73^A0N,39,38^FH\^FDVisitor^FS
    /// ^FO100,100^XG^FN13,1,1^FS
    /// ^FO5,17^GB601,379,8^FS
    /// ^XZ
    private void Example2() {
        Connection connection = new TcpConnection("192.168.1.32", TcpConnection.DEFAULT_ZPL_TCP_PORT);
        try {
            connection.Open();
            ZebraPrinter genericPrinter = ZebraPrinterFactory.GetInstance(connection);
            ZebraPrinterLinkOs linkOsPrinter = ZebraPrinterFactory.CreateLinkOsPrinter(genericPrinter);

            if (linkOsPrinter != null) {
                Dictionary<int, string> vars = new Dictionary<int, string> {
                    { 12, "John" },
                    { 11, "Smith" },
                    { 13, "R:PIC.GRF" }
                };

                linkOsPrinter.PrintStoredFormatWithVarGraphics("E:FORMAT2.ZPL", vars);
            }
        } catch (ConnectionException e) {
            Console.WriteLine(e.ToString());
        } catch (ZebraPrinterLanguageUnknownException e) {
            Console.WriteLine(e.ToString());
        } finally {
            connection.Close();
        }
    }

    /// Print a stored format with the given variables. This ZPL will store a format on a printer, for use with example3.
    /// This example also requires the ANMDS.TTF font to have been download to the printer prior to using this code.
    /// 
    /// ^XA^DFE:FORMAT3.ZPL
    /// ^FS
    /// ^FT26,223^FH^A@N,56,55,E:ANMDS.TTF^CI28^FH\^FN12"Customer Name"^FS
    /// ^FT26,316^FH\^A@N,56,55,E:ANMDS.TTF^FH\^FN11"Invoice Number"^FS
    /// ^FT348,73^FH^A@N,39,38,E:ANMDS.TTF^FH\^FN13"Vendor Name"^FS
    /// ^BY2,4^FT643,376^B7N,4,0,2,2,N^FH\^FDSerial Number^FS
    /// ^FO5,17^GB863,379,8^FS
    /// ^XZ
    private void Example3() {
        Connection connection = new TcpConnection("192.168.1.32", TcpConnection.DEFAULT_ZPL_TCP_PORT);
        try {
            connection.Open();
            ZebraPrinter printer = ZebraPrinterFactory.GetInstance(connection);

            Dictionary<int, string> vars = new Dictionary<int, string> {
                { 12, "东风伟世通汽车饰件系统有限公司" }, // Customer Name
                { 11, "订单号" }, // Invoice Number
                { 13, "供应商名称" } // Vendor Name
            };

            printer.PrintStoredFormat("E:FORMAT3.ZPL", vars, "UTF8");
        } catch (ConnectionException e) {
            Console.WriteLine(e.ToString());
        } catch (ZebraPrinterLanguageUnknownException e) {
            Console.WriteLine(e.ToString());
        } finally {
            connection.Close();
        }
    }
}
See Also