/*
  * Print the provided label and wait a given amount of time
  * (3 seconds) then wait for the printer to be ready again
  * we wait a while to prevent accidental double clicking from the user
  */
 private void PrintAndWait(LabelSetup l, int time = 3000)
 {
     PrintLabels(l);
     Thread.Sleep(time);
     while (!PrinterIsReady())
     {
         ;
     }
 }
        /*
         * Print the labels using the supplied data using the zebra API
         */
        private void PrintLabels(LabelSetup l)
        {
            //Define the label format used to layout the label
            string labelFormat =
                $"^XA" +                                // Start the format
                $"^DFE:LABEL.ZPL^FS" +                  // Set the name of the format file
                $"^PW{l.pagewidth}" +                   // Set the pagewidth
                $"^A@N,{l.fontsize},E:TT0003M_.FNT" +   // Set the font and fontsize
                $"^FO0,{l.offset}" +                    // Set the starting position using the offset
                $"^FB{l.pagewidth},2,0,C" +             // Create a field block to center the text, max 2 lines
                $"^FN1\"Batch Code Text\"^FS" +         // Define the label text into variable slot 1
                $"^XZ";                                 // End the format

            //Send the label format to the printer
            printer.SendCommand(labelFormat);


            //Initialise a dictionary to pass variables to the printer
            Dictionary <int, string> vars = new Dictionary <int, string> {
            };

            //Print each label individually, providing a string for the label text via the dictionary
            for (int i = 0; i < l.quantity; i++)
            {
                if (cancel)
                {
                    break;
                }
                //Change the text based on the size of the label
                if (l.pagewidth < 200)
                {
                    vars[1]  = $"{l.batchcode}\\&";
                    vars[1] += $"{l.prefix}{l.startNumber + i}\\&";
                }
                else
                {
                    vars[1]  = $"{l.batchcode}\\&";
                    vars[1] += $"Bottle: {l.prefix}{l.startNumber + i}\\&";
                }

                //Print the label with associated text
                printer.PrintStoredFormat("E:LABEL.ZPL", vars);
            }
        }