Click or drag to resize

CsvPrinter Class

A class used to print template formats using comma separated values as input data.
Inheritance Hierarchy
SystemObject
  Zebra.Sdk.PrinterCsvPrinter

Namespace:  Zebra.Sdk.Printer
Assembly:  SdkApi_Core (in SdkApi_Core.dll) Version: 2.13.898
Syntax
public class CsvPrinter

The CsvPrinter type exposes the following members.

Methods
  NameDescription
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodStatic memberPrint(Stream, String, String, Stream)
Print template formats using comma separated values as input data.
Public methodStatic memberPrint(Stream, String, String, Stream, Boolean)
Print template formats using comma separated values as input data.
Public methodStatic memberPrint(String, Stream, String, String, Stream)
Print template formats using comma separated values as input data.
Public methodStatic memberPrint(String, Stream, String, String, Stream, Boolean)
Print template formats using comma separated values as input data.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Examples
using System;
using System.IO;
using System.Text;
using Zebra.Sdk.Printer;

public class CsvPrinterExample {

    public static void Main(string[] args) {
        CsvPrintingExample();
        CnCsvPrintingExample();
    }

    /// These examples demonstrate how to use the one-line printing capability of the CsvPrinter class.
    /// 
    /// They assume that a ZPL template containing variable fields appropriate to the CSV data
    /// specified exists on the host device. In this case, a PC with the file named CsvPrinterExampleTemplate.zpl
    /// saved at "c:\CsvPrinterExampleTemplate.zpl". The contents of this file should be...
    /// 
    /// ^XA^DFCsvExamp.zpl^FS
    /// ^A0N,100,100^FO100,100^FN1"Name"^FS
    /// ^A0N,100,100^FO100,200^FN2"Street"^FS
    /// ^A0N,100,100^FO100,300^FN3"City"^FS
    /// ^A0N,100,100^FO100,400^FN4"State"^FS
    /// ^A0N,100,100^FO100,500^FN5"Zip"^FS
    /// ^XZ
    public static void CsvPrintingExample() {
        // The possible inputs to the one-line CSV printing function(s)

        string destinationDevice = "192.168.1.32";

        string templateFilename = "c:\\CsvPrinterExampleTemplate.zpl";
        string defaultQuantityString = "1";
        bool verbose = true;

        // If the destination device argument is 'null' then any data that would have been sent to a destination device,
        // had one been specified, is captured in 'outputDataStream'. This provides a way to test your output and
        // configuration without having an actual printer available or without wasting media even if a printer is
        // available.

        Console.WriteLine("\nThe destinationDevice connection string argument is null:");
        try {
            using (MemoryStream outputDataStream = new MemoryStream()) {
                using (MemoryStream sourceDataStream = GetSampleCsvData()) {
                    CsvPrinter.Print(null, sourceDataStream, templateFilename, defaultQuantityString, outputDataStream, verbose);
                    Console.WriteLine(Encoding.UTF8.GetString(outputDataStream.ToArray()));
                }
            }
        } catch (Exception e) {
            Console.WriteLine(e.ToString());
        }

        // The outputDataStream argument may be null, in which case the data generated by the CsvPrinter class will
        // not be logged but will be sent to the destination device.
        Console.WriteLine("\nThe outputDataStream argument is null:");
        try {
            using (MemoryStream sourceDataStream = GetSampleCsvData()) {
                CsvPrinter.Print(destinationDevice, sourceDataStream, templateFilename, defaultQuantityString, null, verbose);
            }
        } catch (Exception e) {
            Console.WriteLine(e.ToString());
        }

        // Both destinationDevice connection string AND outputDataStream arguments may be specified, in which case the
        // data generated by the CsvPrinter class will be sent to the destination device and logged to the
        // outputDataStream.
        Console.WriteLine("\nBoth destinationDevice connection string and outputDataStream arguments are specified:");
        try {
            using (MemoryStream outputDataStream = new MemoryStream()) {
                using (MemoryStream sourceDataStream = GetSampleCsvData()) {
                    CsvPrinter.Print(destinationDevice, sourceDataStream, templateFilename, defaultQuantityString, outputDataStream, verbose);
                    Console.WriteLine(Encoding.UTF8.GetString(outputDataStream.ToArray()));
                }
            }
        } catch (Exception e) {
            Console.WriteLine(e.ToString());
        }

        // At least one of these two (destinationDevice connection string and outputDataStream) arguments should be specified.
    }

    private static MemoryStream GetSampleCsvData() {
        string sampleCsvData = "John Smith,1234 Anystreet,Anycity,Anystate,12345\nJane Doe,5678 Anyroad,Anytown,Anystate,67890\n";
        return new MemoryStream(Encoding.UTF8.GetBytes(sampleCsvData));
    }

    /// This example demonstrates how to use the one-line printing capability of the CsvPrinter class.
    ///
    /// It assume that a ZPL template containing variable fields appropriate to the CSV data
    /// specified exists on the host device. In this case, a PC with the file named CnCsvPrinterExampleTemplate.zpl
    /// saved at "c:\CnCsvPrinterExampleTemplate.zpl". The contents of this file should be...
    /// 
    /// ^XA^DFE:CnCsvPrinterExampleTemplate.zpl^FS
    /// ^A@N,75,75,E:ANMDS.TTF^CI28^FO0,100^FN1"Customer Name"^FS
    /// ^A@N,75,75,E:ANMDS.TTF^FO0,200^FN2"Component Name"^FS^
    /// ^A@N,75,75,E:ANMDS.TTF^FO0,300^FN3"Vendor Name"^FS
    /// ^A@N,75,75,E:ANMDS.TTF^FO0,400^FN4"Vendor ID"^FS
    /// ^A@N,75,75,E:ANMDS.TTF^FO0,500^FN5"Invoice Number"^FS
    /// ^XZ
    private static void CnCsvPrintingExample() {
        // The possible inputs to the one-line Csv printing function(s)
        string destinationDevice = "192.168.1.32";

        string templateFilename = "C:\\CnCsvPrinterExampleTemplate.zpl";
        string defaultQuantityString = "1";
        bool verbose = true;

        // The outputDataStream argument may be null, in which case the data generated by the CsvPrinter class will
        // not be logged but will be sent to the destination device.
        Console.WriteLine("\nThe outputDataStream argument is null:");
        try {
            using (MemoryStream sourceDataStream = GetSampleCnCsvData()) {
                CsvPrinter.Print(destinationDevice, sourceDataStream, templateFilename, defaultQuantityString, null, verbose);
            }
        } catch (Exception e) {
            Console.WriteLine(e.ToString());
        }
    }

    private static MemoryStream GetSampleCnCsvData() {
        string sampleCnCsvData = "东风伟世通汽车饰件系统有限公司,驾驶员侧仪表板下装饰件,供应商名称,供应商代码,订单号\n";
        return new MemoryStream(Encoding.UTF8.GetBytes(sampleCnCsvData));
    }
}
See Also