.NET Core:使用BarTender
阿新 • • 發佈:2020-09-17
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 = newPrintDocument();
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 }