CsvPrinter Class |
Namespace: Zebra.Sdk.Printer
The CsvPrinter type exposes the following members.
Name | Description | |
---|---|---|
Equals | Determines whether the specified object is equal to the current object. (Inherited from Object.) | |
GetHashCode | Serves as the default hash function. (Inherited from Object.) | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
Print(Stream, String, String, Stream) |
Print template formats using comma separated values as input data.
| |
Print(Stream, String, String, Stream, Boolean) |
Print template formats using comma separated values as input data.
| |
Print(String, Stream, String, String, Stream) |
Print template formats using comma separated values as input data.
| |
Print(String, Stream, String, String, Stream, Boolean) |
Print template formats using comma separated values as input data.
| |
ToString | Returns a string that represents the current object. (Inherited from Object.) |
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)); } }
using Android.App; using Android.OS; using Android.Views; using Android.Widget; using System; using System.IO; using System.Text; using System.Threading.Tasks; using Zebra.Sdk.Printer; public class CsvPrinterExample : Activity { protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); LinearLayout layout = (LinearLayout)View.Inflate(this, Android.Resource.Layout.ActivityListItem, null); layout.Orientation = Orientation.Vertical; Button buttonPrint = new Button(this) { Text = "Run Csv Printer Example", LayoutParameters = new ViewGroup.LayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent)) }; layout.AddView(buttonPrint); SetContentView(layout); buttonPrint.Click += async (sender, e) => { await Task.Run(() => { // The possible inputs to the one-line CSV printing function(s) string destinationDevice = "1.2.3.4"; CsvPrintingExample(destinationDevice); CnCsvPrintingExample(destinationDevice); }); }; } /// 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 void CsvPrintingExample(string destinationDevice) { 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 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 void CnCsvPrintingExample(string destinationDevice) { 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 MemoryStream GetSampleCnCsvData() { string sampleCnCsvData = "东风伟世通汽车饰件系统有限公司,驾驶员侧仪表板下装饰件,供应商名称,供应商代码,订单号\n"; return new MemoryStream(Encoding.UTF8.GetBytes(sampleCnCsvData)); } }
using CoreGraphics; using System; using System.IO; using System.Text; using System.Threading.Tasks; using UIKit; using Zebra.Sdk.Printer; public class CsvPrinterExample : UIViewController { public CsvPrinterExample(IntPtr handle) : base(handle) { UIButton testButton = new UIButton(UIButtonType.System) { Frame = new CGRect(25, 25, 300, 150) }; testButton.SetTitle("Run Csv Printer Example", UIControlState.Normal); testButton.TouchUpInside += async (sender, e) => { await Task.Run(() => { // The possible inputs to the one-line CSV printing function(s) string destinationDevice = "1.2.3.4"; CsvPrintingExample(destinationDevice); CnCsvPrintingExample(destinationDevice); }); }; View.AddSubview(testButton); } /// 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 void CsvPrintingExample(string destinationDevice) { 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 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 void CnCsvPrintingExample(string destinationDevice) { 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 MemoryStream GetSampleCnCsvData() { string sampleCnCsvData = "东风伟世通汽车饰件系统有限公司,驾驶员侧仪表板下装饰件,供应商名称,供应商代码,订单号\n"; return new MemoryStream(Encoding.UTF8.GetBytes(sampleCnCsvData)); } }