I have a C# WPF application that is supposed to print labels from a Zebra printer. The Zebra printer is setup as a generic text printer (as opposed to using a Zebra/other driver). The label's ZPL code is already generated and when I print the ZPL code from a text editor such as Notepad or Notepad++, the label prints perfectly fine. When I print the same string from my WPF application, I get different results.
What could be causing theses different results? I've verified and re-copied the ZPL code into my application several times, so I'm quite confident the ZPL is the same. Is there a better method of printing via C# WPF applications? The idea is to allow the user to setup the Zebra printer as a standard Windows printer and select it at print time from the PrintDialog.
Here is my code for printing:
System.Windows.Controls.PrintDialog prnt = new PrintDialog();
prnt.PageRangeSelection = PageRangeSelection.AllPages;
prnt.UserPageRangeEnabled = false;
Nullable<bool> result = prnt.ShowDialog();
if (result == true)
{
string zpl = "^XA" + Environment.NewLine +
"^RS,,,3,N,,,2" + Environment.NewLine +
"^RR3" + Environment.NewLine +
"^XZ" + Environment.NewLine +
"^XA" + Environment.NewLine +
"^SZ2^JMA" + Environment.NewLine +
"^MCY^PMN" + Environment.NewLine +
"^PW459" + Environment.NewLine +
"^LT41" + Environment.NewLine +
"~JSN" + Environment.NewLine +
"^MD30" + Environment.NewLine +
"^JZY" + Environment.NewLine +
"^LH0,0^LRN" + Environment.NewLine +
"^XZ" + Environment.NewLine +
"^XA" + Environment.NewLine +
"^FT31,42" + Environment.NewLine +
"^CI0" + Environment.NewLine +
"^A0N,23,31^FDAsset ID:^FS" + Environment.NewLine +
"^FT31,74" + Environment.NewLine +
"^A0N,23,31^FDA0000001^FS" + Environment.NewLine +
"^FT31,106" + Environment.NewLine +
"^A0N,23,31^FDItem Code:^FS" + Environment.NewLine +
"^FT31,137" + Environment.NewLine +
"^A0N,23,31^FD500124^FS" + Environment.NewLine +
"^FT49,324" + Environment.NewLine +
"^A0N,23,31^FDShuttleworth conveyor^FS" + Environment.NewLine +
"^FT49,346" + Environment.NewLine +
"^A0N,23,31^FDnylon rollers - A^FS" + Environment.NewLine +
"^FT49,369" + Environment.NewLine +
"^A0N,23,31^FDsection of roller is 4-1/2^FS" + Environment.NewLine +
"^FT49,392" + Environment.NewLine +
"^A0N,23,31^FDlong with a deep pocket...^FS" + Environment.NewLine +
"^FT31,172" + Environment.NewLine +
"^A0N,23,31^FDMfgr Part:^FS" + Environment.NewLine +
"^FT31,202" + Environment.NewLine +
"^A0N,23,31^FD701646-231A^FS" + Environment.NewLine +
"^FT31,254" + Environment.NewLine +
"^A0N,23,31^FDStore:^FS" + Environment.NewLine +
"^FT258,254" + Environment.NewLine +
"^A0N,23,31^FDBin:^FS" + Environment.NewLine +
"^FT31,289" + Environment.NewLine +
"^A0N,23,31^FDB5 Maint^FS" + Environment.NewLine +
"^FT258,289" + Environment.NewLine +
"^A0N,23,31^FDE6B^FS" + Environment.NewLine +
"^FO258,23" + Environment.NewLine +
"^BY1^BCN,38,N,N^FD>:A0>5000001^FS" + Environment.NewLine +
"^FO258,87" + Environment.NewLine +
"^BCN,38,N,N^FD>;500124^FS" + Environment.NewLine +
"^RFW,H,1,2,1^FD1400^FS" + Environment.NewLine +
"^RFW,H,2,4,1^FDA0000001^FS" + Environment.NewLine +
"^PQ1,0,1,Y" + Environment.NewLine +
"^XZ" + Environment.NewLine;
var doc = new FlowDocument();
doc.ColumnWidth = prnt.PrintableAreaWidth;
Paragraph p = new Paragraph();
p.Inlines.Add(zpl);
doc.Blocks.Add(p);
prnt.PrintDocument(((IDocumentPaginatorSource)doc).DocumentPaginator, "Label A0000001");
//doc.Blocks.Add(new Paragraph(new Run(zpl)));
//prnt.PrintDocument(((IDocumentPaginatorSource)doc).DocumentPaginator, "Label A0000001");
//prnt.PrintDocument((Section)XamlReader.Parse(zpl));
}
Here are the results of printing labels from the text editor (left) vs my application (right):