前提條件:
安裝Bartender打印軟件,我用的是10.1,然後用註冊機註冊,註冊後版本選擇Enterprise Automation
註冊機下載地址:https://download.csdn.net/download/horseroll/11687585
源碼下載地址:https://download.csdn.net/download/horseroll/11687678
1.項目中引用Seagull.BarTender.Print.dll文件,安裝目錄SDK文件夾下有,實在找不到,下載源碼,裏面有
2.代碼編寫
LabelFormatDocument format;
Engine engine = new Engine(true);
string previewPath = Application.StartupPath + "\\test.btw";
format = engine.Documents.Open(previewPath);
Seagull.BarTender.Print.Messages messages;
format.Print("Select printer", out messages);
有以上幾行代碼就可以進行打印了
3.如果說需要把文件進行輸出圖片預覽
string previewPath = Application.StartupPath;//文件路徑
format.ExportPrintPreviewToFile(previewPath, "PrintPreview" + textBox1.Text + ".jpg", ImageType.JPEG, Seagull.BarTender.Print.ColorDepth.ColorDepth24bit, new Resolution(picPreview.Width, picPreview.Height), System.Drawing.Color.White, OverwriteOptions.Overwrite, true, true, out messages);
ShowImage(new Bitmap(previewPath + "\\PrintPreview" + textBox1.Text + "1.jpg"));//進行PictureBox顯示
4.如果BTW模板文件中有數據需要動態加載的
format.SubStrings["test1"].Value = textBox1.Text;
format.SubStrings["test2"].Value = textBox2.Text;