2

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.

3
  • Provide a sample ZPL output and a sample label image to see what exactly is happening. Commented Aug 25, 2014 at 11:53
  • Can you please post the ZPL which is getting built. Also As you are generating your template in the Zebra Designer pro what kind of label are you using as placeholders to get the values. Commented Aug 25, 2014 at 11:56
  • 1
    We are using input fields to create placeholders and pass parameters which get placed in those input fields Commented Aug 25, 2014 at 12:40

1 Answer 1

5

Dont use input fields. replace input fields in the code as follows:

  1. Open the label where you need to add a new field(parameter to be displayed).
  2. On the Toolbox, Choose Text > Fixed Text.
  3. Enter the parameter name. Note that the string should be such that it can be searched and replaced with the parameter value from database. Click Finish

enter image description here

Generate the ZPL for the file using print to file option in Print dialogbox. The ZPL file which will be generated will consist of the parameter names as mentioned in the text wizrd dialog box.

Use this ZPL file in the code. Now instead of passing parameter values using ZPL file use the ZPL file which has been generated and replace the values in place of the paramter name as follows:

//pass the zpl generated from Zebra Designer Pro into this menthod
public string replaceParameterValues(string zplForLabel)
{
    StringBuilder zpl = new StringBuilder();
    zpl.Apppend(zplForLabel);
    //do this for all the paramters
    zpl = zpl.Replace("<ParemeterName>", valueForTheParamter);

    //pass this zpl to the printer for printing as it will contain 
    //all the values for the parameters 
    return zpl.ToString();
}

This will remove your dependency to create ZPL for passing parameters.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks a lot Nipun. its really hard to believe that this thing will work this way as well and we can entirely get rid of the trouble to generate ZPL file ourselves. This works really cool.
To any wayward travelers using Code39, The output of ZPL for a 39 barcode of lowercase appends a + character. The <,> are also converted. I am using . and all uppercase letters to use this functionlity for example: .SERIALBAR. and ZPLString = ZPLString.Replace(".SERIALBAR.", Serial);
This approach doesn't seem to be working if i use any font other than Zebra Fonts, since the text is then generated as Graphic Field. Is there a way I can handle such situation?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.