How to use the same ZPL code on printers with different dpi [closed]

4

Expensive,

I've been using ZebraDesigner2 software to create ZPL labels for printing on the GC420t for some time and I'm not having any problems. Now I have to generate ZPL code for label printing using the S4M (200 dpi) and ZT230 (300 dpi) printers. The problem is the difference in dpi of the labels, which makes printing done by S4M very large, cutting out important information.

Ex:

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

I have tried the following commands, but I have not found good examples.

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

I need the print on both printers to be the same regardless of whether it's 200 or 300 dpi.

Thank you in advance.

    
asked by anonymous 19.10.2015 / 21:56

2 answers

0

What if you show a screen for the user to choose the printer and you create a dynamic configuration in ZPL code generation? So that would not work?

    
30.03.2016 / 14:46
0

I did the following, I maintain a printer registry where I have the DPI information of it and I create all my zpl templates in the 300 DPI standard when I need to convert 300 to 200 DPI with the function below, I'm already using the for at least 5 months and is serving very well.

I just can not 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;
}
    
30.03.2016 / 15:16