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;
}