I've created a class for dymo labelprinters
using DymoSDK.Implementations;
using DymoSDK.Interfaces;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VoorraadBeheer.Classes
{
public class DymoPrinters
{
public List<IPrinter> DymoPrinterList;
public List<IPrinter> FullDymoPrinterList;
private IDymoPrinter tmpIDymoPrinter;
private IDymoLabel tmpIDymoLabel;
public void Initialize()
{
if (null == System.Windows.Application.Current)
{
new System.Windows.Application();
}
DymoSDK.App.Init();
tmpIDymoPrinter = DymoPrinter.Instance;
tmpIDymoLabel = DymoLabel.Instance;
FullDymoPrinterList = tmpIDymoPrinter.GetPrinters().Result.ToList();
DymoPrinterList = new List<IPrinter>();
foreach (IPrinter printer in FullDymoPrinterList)
{
if (printer.IsConnected)
{
DymoPrinterList.Add(printer);
}
}
}
public string LoadLabelXml(string LabelPath)
{
tmpIDymoLabel.LoadLabelFromFilePath(LabelPath);
return tmpIDymoLabel.XMLContent;
}
public IDymoLabel MakeLabelFromXml(string LabelXml)
{
tmpIDymoLabel.LoadLabelFromXML(LabelXml);
return tmpIDymoLabel;
}
public bool PrintLabel(IDymoLabel label, string PrinterName, int amount = 1)
{
return tmpIDymoPrinter.PrintLabel(label, PrinterName, amount).Result;
}
public async Task <int> GetRemainingLabels(string PrinterName)
{
rollstatus = string.Empty;
labelsremaining = 0;
labelname = string.Empty;
var tmpi = await DymoPrinter.Instance.GetRollStatusInPrinter(PrinterName);
if (tmpi != null)
{
rollstatus = tmpi.RollStatus.ToString();
labelsremaining = Convert.ToInt32(tmpi.LabelsRemaining);
labelname = tmpi.Name;
return labelsremaining;
}
return -1;
}
public string rollstatus { get; set; }
public int labelsremaining { get; set; }
public string labelname { get; set; }
}
}