How to use the same ZPL code on different dpi printers

Asked

Viewed 303 times

4

Expensive,

For some time I have been using Zebradesigner2 software to create ZPL labels for printing on Gc420t and I’m not having problems. Now I have to generate ZPL code for label printing using the printers S4M (200 dpi) and ZT230 (300 dpi) the problem is the difference of dpi of the same, that makes the impression made by S4M come out very big cutting important information.

Ex:

^XA
^PW1240
^LL1724
^FT321,845^A0N,42,40^FH\^FDTeste 1234567890^FS
^PQ1,0,1,Y^XZ

I tried using the commands below, but I did not find good examples.

^MU – Set Units of Measurement
^JM – Set Dots per Millimeter

I need the printing on both printers to be the same no matter whether it’s in 200 or 300 dpi.

Thanks in advance.

2 answers

0

What if you show a screen for the user to choose the printer and you create a dynamic configuration in the generation of ZPL code? So it wouldn’t work?

0

I did as follows, I keep a register of printers where I have the same DPI information and create all my zpl templates in the standard 300 DPI when it is necessary to convert from 300 to 200 DPI with the function below, I have been using for at least 5 months and is serving very well.

I just can’t convert images :(

public static string RemoveNonNumbers(this string source) {
 return Regex.Replace(source, @ "[^0-9]+", "");
}

public static string ConvertTo200DPI(string zplCommands) {
 string cmdReady = string.Empty;

 using(StringReader reader = new StringReader(zplCommands)) {
  string[] keyCmds = {
   "FT",
   "A0I",
   "A0R",
   "GB",
   "FO",
   "BY",
   "A0N",
   "FB"
  };

  string line;
  while ((line = reader.ReadLine()) != null) {
   string newLine = line;
   const decimal ActualDpi = 300 m;
   const decimal ExpectedDpi = 200 m;

   string[] cmds = line.Split('^');
   foreach(var cmd in cmds) {
    if (keyCmds.Any(x => cmd.Replace("^", "").Contains(x))) {
     string oldValue = string.Empty;
     string newValue = string.Empty;

     string[] values = cmd.Split(',');
     if (values.Length >= 1) {
      if (!keyCmds.Any(x => values[0] == x)) {
       string val = values[0].RemoveNonNumbers();
       if (!string.IsNullOrEmpty(val)) {
        newValue = ((int)((Convert.ToInt32(val) / ActualDpi) * ExpectedDpi)).ToString();
       }
       oldValue = values[0].RemoveNonNumbers();
      }
     }
     if (values.Length >= 2) {
      if (!string.IsNullOrEmpty(oldValue)) {
       newValue += ",";
       oldValue += ",";
      }

      string val = values[1].RemoveNonNumbers();
      if (!string.IsNullOrEmpty(val)) {
       newValue += ((int)((Convert.ToInt32(val) / ActualDpi) * ExpectedDpi));
      }
      oldValue += values[1].RemoveNonNumbers();
     }
     if (values.Length >= 3) {
      if (!string.IsNullOrEmpty(oldValue)) {
       newValue += ",";
       oldValue += ",";
      }
      string val = values[2].RemoveNonNumbers();
      if (!string.IsNullOrEmpty(val)) {
       newValue += ((int)((Convert.ToInt32(values[2].RemoveNonNumbers()) / ActualDpi) * ExpectedDpi));
      }
      oldValue += values[2].RemoveNonNumbers();
     }

     if (!string.IsNullOrEmpty(oldValue)) newLine = newLine.Replace(cmd, cmd.Replace(oldValue, newValue));
    }
   }

   cmdReady += newLine + System.Environment.NewLine;
  }
 }

 return cmdReady;
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.