之前公司标签一直用ZPL开发,前段时间公司购买了bartender软件用于标签设计。功能大大的,没得说。废话少说了,进入正题。
需求:标签模板已经设计好,设计个简单程序调用该标签模板并打印。(标签变量通过程序传递)
以下为简单写的winform打印程序
程序界面:
代码如下(其中一个标签类型的代码,其他省略):
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace CS_label_Print
{
public partial class BOX_Label : Form
{
public BOX_Label()
{
InitializeComponent();
}
BarTender.Application btApp;
BarTender.Format btFormat;
private void btn2_Click(object sender, EventArgs e)
{
int a = Int32.Parse(this.num2.Value.ToString());//设置打印数量的变量
if (this.TXT3.Text.Length == 0 || this.TXT4.Text.Length == 0)
{
MessageBox.Show("未输入料号或者QTY");
}
else
{
btFormat = btApp.Formats.Open(@"c:\BarTenderFiles\CS\CS_Package Label", false, "");
btFormat.PrintSetup.IdenticalCopiesOfLabel = 1; //设置同序列打印的份数
btFormat.PrintSetup.NumberSerializedLabels = a; //设置需要打印的序列数
btFormat.SetNamedSubStringValue("SN", this.TXT3.Text); //向bartender模板传递变量
btFormat.SetNamedSubStringValue("QTY", this.TXT4.Text);
btFormat.PrintOut(false, false); //第二个false设置打印时是否跳出打印属性
btFormat.Close(BarTender.BtSaveOptions.btSaveChanges); //退出时是否保存标签
}
}
private void BOX_Label_Load(object sender, EventArgs e)
{
btApp = new BarTender.Application();
this.num2.Value = 1;
}
private void BOX_Label_FormClosed(object sender, FormClosedEventArgs e)
{
btApp.Quit(BarTender.BtSaveOptions.btSaveChanges);//界面退出时同步退出bartender进程
}
}
}本文出自 “书到用时方恨少” 博客,谢绝转载!
C# 调用Bartender服务并打印bartender标签
原文:http://7798914.blog.51cto.com/7788914/1662036