I want to print data on a label.
I created a ZPL template file and in my application i read that template file, look up a specific string, replace that string with data from my application and then send it to the printer.
When I trigger the printer over the webserver to print the template, everything is fine.
But when i trigger the print with my application, i get the desired label first AND then he prints a second label right after that, that only contains a few equally sized black bars on it and i dont know why.
This is the code that connects to my printer, interprets the label template and sends the commands for printing to the printer:
public void PrintLabel(string TemplateFile, LabelContent cont)
{
logger.Info("Trying to print label at printer " + set.IP + " ...");
string content;
// read template
content = File.ReadAllText(TemplateFile);
// loop over all attributes
foreach (var prop in cont.GetType().GetProperties())
{
var srch = "*" + prop.Name + "*";
var rplc = prop.GetValue(cont, null).ToString(); // simple datatype
logger.Trace("Trying to find/replace [" + srch + "] with [" + rplc + "]");
content = content.Replace(srch, rplc);
}
var lines = content.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
// print it
var eth = new TSCSDK.ethernet();
if (eth.openport(set.IP, set.Port))
{
foreach (var l in lines)
{
logger.Debug("[" + set.IP + "]: prn.line: " + l);
eth.sendcommand(l);
}
eth.printlabel("1", "1");
eth.closeport();
logger.Info("[" + set.IP + "]: Done. Label printed");
}
else
{
throw new Exception("[" + set.IP + "]: Error opening tcp connection to printer");
}
}
