近期用bartend,有兩種方法可以呼叫
1.呼叫bartend.exe
2.採用bartend.dll(版本11.1.3.1)
工具
1.bartend版本 :BarTender Designer 2019 R3 Enterprise 版本
2.VS2019 C#
c#
方法1:呼叫bartend.exe
//宣告P,執行其它外部程式
  Process p;
 //載入位置 
 BarTend = @"C:\Program Files\Seagull\BarTender 2019\bartend.exe";//執行Bartend.exe
 Template = @"C:\test\temp.btw";//列印的樣版
 PrintValue = @"C:\test\textcontent.txt";//內容
 
  private void button1_Click(object sender, EventArgs e)
        {
            string sub_nam = @"/F="+ Template + " /D="+ PrintValue + " /P /X " + Convert.ToChar(10);
            try
            {
                //啟動處理序
                p = Process.Start(BarTend, sub_nam);//start(執行檔,傳遞值)
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
            finally {
                if (p != null)
                {
                    p.Close();
                    p.Dispose();
                    p = null;
                }
            }
        
        }
Bartend方面
資料庫->右鍵資料庫連線設定->下圖,再選擇列印的內容,例如:txt,csv
這裡要先指定,否則再c#再傳送新的列印內容,它會出現警告-找不到印的內容的檔案
優點:c# 程式簡單,只要呼叫bartend.exe就可以列印
缺點:c# 點擊多次Process.statr 反而呼叫bartend.exe沒有反應,要多按幾次
方法2:採用bartend.dll(版本11.1.3.1)
滙入DLL
來源: C:\Program Files\Seagull\BarTender 2019\SDK\Assemblies\Seagull.BarTender.Print.dll
C#
using Seagull.BarTender.Print; //重要
  private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                Engine btEngine = new Engine();
                btEngine.Start();
                string lj = @"C:\test\btwtest.btw";
                LabelFormatDocument btFormat = btEngine.Documents.Open(lj);
             
                //對模版相應欄位進行賦值
                btFormat.SubStrings["1"].Value = "44";
                btFormat.SubStrings["2"].Value = "55";
                btFormat.SubStrings["3"].Value = "FRVGT789";
                //指定印表機名
                btFormat.PrintSetup.PrinterName = "標籤機名字";
                //改變標籤列印數份連載
                btFormat.PrintSetup.NumberOfSerializedLabels = 1;
                //列印份數                  
                btFormat.PrintSetup.IdenticalCopiesOfLabel = 1;
                Messages messages;
                int waitout = 10000; // 10秒 超時
                Result nResult1 = btFormat.Print("標籤列印軟體", waitout, out messages);
                btFormat.PrintSetup.Cache.FlushInterval = CacheFlushInterval.PerSession;
                //不儲存對開啟模板的修改
                //btFormat.Close(SaveOptions.DoNotSaveChanges);
                //結束列印引擎                 
                btEngine.Stop();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Exception: " + ex.Message);
                return;
            }
        }
bartend方面
拉下物件,如下圖
拉下”文字”按右鍵選”屬性”,找到”資料來源”->文字範例,將”名稱”設1。
PS: ”名稱”設1是c#列印內容
選QRCode,將文字(12345678)給隱藏,用屬性->選”123可讀性”->點”無”。

找到”資料來源”將”名稱”設3。
C#進行列印會出現錯誤
執行程式(RUN)時
System.BadImageFormatException   HResult=0x8007000B   Message=無法載入檔案或組件 'Seagull.BarTender.Print, Version=11.1.3.1, Culture=neutral, PublicKeyToken=109ff779a1b4cbc7' 或其相依性的其中之一。
解決方法
專案->屬性->應用程式->目標Framework將4.6.1 改為 4.0
改NET.Framework4 即可
但我再改回用Framework將4.6.1,就不會出現錯了。
PS:可能舊版改回來沒效