We are using Zebra Designer Pro to create the templates. We have placed various labels on the templates to which we pass values dynamically through the code at the runtime.
We are doing this by creating ZPL in the code and appending various parameter values which we want to print in the ZPL. Method to create the label is below:
private string GetPrinterInstruction(string templateName, IList<string> variables, int numberOfCopies)
{
StringBuilder printerInstruction = new StringBuilder();
//start the label format and sets the field origin
printerInstruction.AppendLine("^XA");
//Template
printerInstruction.AppendLine("^XF");
printerInstruction.AppendLine(templateName);
//Field Separator
printerInstruction.AppendLine("^FS");
// for each Variable
for (var i = 1; i <= variables.Count; i++)
{
//Assign field number FN1..FN2
printerInstruction.AppendLine("^FN");
printerInstruction.AppendLine(i.ToString());
//Indicate start of field data
printerInstruction.AppendLine("^FD");
//Field data
printerInstruction.AppendLine(variables[i - 1]);
//Field Separator
printerInstruction.AppendLine("^FS");
}
//Printing Quantities of Labels,
printerInstruction.AppendLine("^PQ" + numberOfCopies);
//indicates the end of the print field and the end of the label format.
printerInstruction.AppendLine("^XZ");
return printerInstruction.ToString();
}
void PrintLabel(CasthouseDataContext casthouseDataContext, Printer printer, LabelType.LabelTypeCodes labelTypeCode, IList<string> variables, int numberOfCopies)
{
try
{
string printerInstruction = GetPrinterInstruction(templateName, variables, numberOfCopies);
CodePrinter.SendStringToPrinter(printerName, labelTemplateName, printerInstruction);
}
catch (Exception ex)
{
ExceptionManager.HandleException(ex, ExceptionPolicies.Service);
}
}
Below please find the ZPL file which is being generated to pass parameters to the template on the printer:
^XA
^XF
E:Label.ZPL
^FS
^FN
1
^FD
^FS
^FN
2
^FD
^FS
^FN
3
^FD
^FS
^FN
4
^FD
EEEEEEEEEEE
^FS
^FN
5
^FD
BBBBBBBBBB
^FS
^FN
6
^FD
11111111
^FS
^FN
7
^FD
16/08/2014
^FS
^FN
8
^FD
2411
^FS
^FN
9
^FD
11
^FS
^FN
10
^FD
2422
^FS
^FN
11
^FD
644444
^FS
^FN
12
^FD
6
^FS
^FN
13
^FD
1
^FS
^FN
14
^FD
^FS
^FN
15
^FD
^FS
^FN
16
^FD
6
^FS
^FN
17
^FD
^FS
^FN
18
^FD
ACCCCC
^FS
^FN
19
^FD
^FS
^FN
20
^FD
ABCCCC
^FS
^FN
21
^FD
^FS
^FN
22
^FD
66666666
^FS
^FN
23
^FD
666666
^FS
^FN
24
^FD
NNNNNNNNN
^FS
^FN
25
^FD
^FS
^FN
26
^FD
ABCCC
^FS
^FN
2222222
^FD
1111111111
^FS
^FN
28
^FD
111111
^FS
^FN
29
^FD
111111111
^FS
^FN
30
^FD
1111111111
^FS
^PQ1
^XZ
But the data which is getting printed on the labels is consistent and gets misplaced as we are not getting data in right placeholders. Please help as to how we can fix the issue.
