BarTender官方的SDK只支持.NET Framework,無法在.NET Core環境下使用。但其實.NET Core環境下還是有辦法使用BarTender的,那就是直接調用底層的COM組件。
在項目中添加引用COM:Interop.BarTender
案例代碼:
1 public void Print(List<PrinterInput> inputs) 2 { 3 BarTender.Application BtApp = new BarTender.Application(); 4 PrintDocument printDoc = new PrintDocument();
7 BarTender.Format btFormat = BtApp.Formats.Open(Path.Combine(AppContext.BaseDirectory, "Template", "Label.btw")); 8 btFormat.PrintSetup.Printer = printDoc.PrinterSettings.PrinterName;
19 foreach (var input in inputs) 20 { 21 btFormat.SetNamedSubStringValue("PartNum", input.PartNum); 22 btFormat.SetNamedSubStringValue("PartDescription", input.PartDescription); 23 btFormat.SetNamedSubStringValue("LotNum", input.LotNum); 24 btFormat.SetNamedSubStringValue("Qty", input.Qty); 25 btFormat.PrintOut(); 26 }
28 btFormat.Close(BarTender.BtSaveOptions.btDoNotSaveChanges); 29 BtApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);
31 }