C#调用barTender打印标签示例

这篇具有很好参考价值的文章主要介绍了C#调用barTender打印标签示例。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

使用的电脑需要先安装BarTender 

C#调用barTender打印标签示例,c#,开发语言 

 

C#调用barTender打印标签示例,c#,开发语言 我封装成一个类

using System;
using System.Windows.Forms;

namespace FT_Tools
{
    public class SysContext
    {
        public static BarTender.Application btapp = new BarTender.Application();
        public static BarTender.Format btFormat;
        public void Quit()
        {
            SysContext.btapp.Quit(BarTender.BtSaveOptions.btSaveChanges);//界面退出时同步退出bartender进程
        }

        private static bool btPrint_Test(string modelPath,string txt,string barcode )
        {
            try
            {
                btFormat = btapp.Formats.Open(modelPath, false, ""); //System.Windows.Forms.Application.StartupPath + @"\1.btw"
                btFormat.PrintSetup.IdenticalCopiesOfLabel = 1;//打印份数
                btFormat.PrintSetup.NumberSerializedLabels = 1;//序列标签数
                btFormat.SetNamedSubStringValue("打印文本", txt.Trim());
                btFormat.SetNamedSubStringValue("打印条码", barcode.Trim());
                btFormat.PrintOut(true, false);//第二个false设置打印时是否跳出打印属性
                btFormat.Close(BarTender.BtSaveOptions.btSaveChanges); //退出时是否保存标签
                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return false;
            }
        }
    }

}

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace BarTenderDemo
{
    public partial class Form1 : Form
    {
        private BarTender.Application btAPP;
        private BarTender.Format btFormat;

        //SELECT MaterielId,ProductBigPackId,NetWeight,GrossWeight,num 
        //FROM Make_ProductBigPack mpb
        //LEFT JOIN Make_TaskInfo mti ON mpb.TaskId=mti.TaskId
        //WHERE ProductBigPackId=''

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            btAPP = new BarTender.Application();
        }

        private void btPrint_Click(object sender, EventArgs e)
        {
            try
            {
                btFormat = btAPP.Formats.Open(System.Windows.Forms.Application.StartupPath+@"\1.btw", false, "");
                btFormat.PrintSetup.IdenticalCopiesOfLabel = 1;//打印份数
                btFormat.PrintSetup.NumberSerializedLabels = 1;//序列标签数
                btFormat.SetNamedSubStringValue("打印文本", txtMemo.Text.Trim());
                btFormat.SetNamedSubStringValue("打印条码", txtBarcode.Text.Trim());
                btFormat.PrintOut(true, false);//第二个false设置打印时是否跳出打印属性
                btFormat.Close(BarTender.BtSaveOptions.btSaveChanges); //退出时是否保存标签
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            btAPP.Quit(BarTender.BtSaveOptions.btSaveChanges);//界面退出时同步退出bartender进程
        }
    }
}

示例2:与上面一样的。文章来源地址https://www.toymoban.com/news/detail-681811.html

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Runtime.InteropServices;
using BarTender;
using System.Text;
using Newtonsoft.Json;


namespace bartenderService
{
    /// <summary>
    /// BartenderWebService 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。 
    // [System.Web.Script.Services.ScriptService]

    public class SysContext
    {
        public static BarTender.Application btapp = new BarTender.Application();
        public static BarTender.Format btfat;
    }
    public class BartenderWebService : System.Web.Services.WebService
    {
        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }


        [WebMethod]
        public string GetTestLabelJson()
        {
            printContext pt=new printContext();
            pt.data = new List<printCell>();
            printCell cell=new printCell();
            pt.modelName = "气体检测仪.btw";
            pt.printDateStr = "生产日期";
            pt.printFBStr = "防爆证号";
            pt.printGasStr = "测量气体";
            pt.printSNStr = "产品编号";
            pt.printTELStr = "热线电话";
            pt.printVolStr = "工作电压";
            pt.printRangeStr = "检测范围";
            cell.printDate = "2019.12";
            cell.printFB = "CNEX17.0263";
            cell.printGas = "可燃气体";
            cell.printRange = "0-100";
            cell.printVol = "24V";
            cell.printUnit = "%LEL";
            cell.printSN = "226013221";
            pt.data.Add(cell);
            cell.printGas = "氨气";
            cell.printUnit = "PPM";
            pt.data.Add(cell);
            return JsonConvert.SerializeObject(pt);
        }

        [WebMethod]
        public string PrintLabel(string jsonstr)
        {
            int printcount = 0,i=0;
            string path = System.AppDomain.CurrentDomain.BaseDirectory + "model";
            string file_ini = path + "\\configure.ini";
            //pt.modelName + pt.data[1].printRange + pt.data[1].printGas
            //Newtonsoft.Json.Linq.JArray.Parse(jsonstr);
            printContext pt = JsonConvert.DeserializeObject<printContext>(jsonstr);
            if (pt.modelName == null)
                pt.modelName = "";
            if (pt.modelName == "")
                pt.modelName = "气体检测仪.btw";
            try
            {
                SysContext.btfat = SysContext.btapp.Formats.Open(path + "\\" + pt.modelName, false, "");
            }
            catch
            {
                pt.modelName = "气体检测仪.btw";
                SysContext.btfat = SysContext.btapp.Formats.Open(path + "\\" + pt.modelName, false, "");
            }
            SysContext.btfat.PrintSetup.IdenticalCopiesOfLabel = 1;
            SysContext.btapp.Visible = false;
            printcount = pt.data.Count();
            for(i=0;i<printcount;i++)
            {
                SysContext.btfat.SetNamedSubStringValue("BT_Gas", String.Format(pt.printGasStr+":"+pt.data[i].printGas));
                SysContext.btfat.SetNamedSubStringValue("BT_Range", String.Format(pt.printRangeStr+":"+pt.data[i].printRange+ pt.data[i].printUnit));
                SysContext.btfat.SetNamedSubStringValue("BT_Vol", String.Format(pt.printVolStr + ":" + pt.data[i].printVol));
                SysContext.btfat.SetNamedSubStringValue("BT_SN", String.Format(pt.printSNStr + ":" + pt.data[i].printSN));
                SysContext.btfat.SetNamedSubStringValue("BT_DATE", String.Format(pt.printDateStr + ":" + pt.data[i].printDate));
                SysContext.btfat.SetNamedSubStringValue("BT_FB", String.Format(pt.printFBStr + ":" + pt.data[i].printFB));
                if(pt.data[i].printTEL!=""&& pt.data[i].printTEL !=null)
                    SysContext.btfat.SetNamedSubStringValue("BT_TEL", String.Format(pt.printTELStr + ":" + pt.data[i].printTEL));
                SysContext.btfat.PrintOut(false, false);
            } 
            return "ok";
        }

    }
}

到了这里,关于C#调用barTender打印标签示例的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • C# 任务并行类库Parallel调用示例

    Task Parallel Library 是微软.NET框架基础类库(BCL)中的一个,主要目的是为了简化并行编程,可以实现在不同的处理器上并行处理不同任务,以提升运行效率。Parallel常用的方法有For/ForEach/Invoke三个静态方法。

    2024年02月04日
    浏览(26)
  • 【Lua in Unity】详解与和C#互相调用示例

    目录 Lua在Unity中的主要作用 如何创建 Lua与C#互相调用 C#和Lua的使用场景区分 完整示例 游戏逻辑编写:Lua可以作为一种脚本语言,用于游戏中的逻辑编写,例如定义游戏角色的行为、AI逻辑,处理游戏的战斗逻辑和流程控制,等等。可以将Lua代码通过Unity的API来实现与引擎的交

    2024年02月11日
    浏览(43)
  • 调用示例、python语言调用翔云发票查验接口、发票OCR接口

    python语言调用翔云发票查验接口、发票OCR接口其实方法很简单,只需要能看懂开发代码,然后在翔云开发者中,下载所需要的语言开发示例,更换产品参数即可。 发票管理是企业日常工作中不可或缺的一环,但传统的发票查验和识别方式效率低下,给企业带来了很大的负担。

    2024年04月26日
    浏览(30)
  • (一)Qt+OpenCV调用海康工业相机SDK示例开发

    提示:这里是该系列文章的所有文章的目录 第一章: (一)Qt+OpenCV调用海康工业相机SDK示例开发 第二章: (二)Qt多线程实现海康工业相机图像实时采集 近期在Qt环境下进行海康工业相机的使用开发,发现海康提供的示例没有Qt的demo,而其中有基于MFC框架的示例,所以在这

    2024年02月03日
    浏览(50)
  • C#开发Windouw窗体之Form窗体及示例(基础)

    Forms窗体也称为窗口,通过窗体可以显示信息、请求用户输入以及通过网络与远程计算机通信。 我们首先要明白三点: 1.窗体也是对象,窗体类定义了生成窗体的模板,每当实例化一个窗体类,就产生一个窗体 2.Form类是所有窗体类的基类。 3.在一个项目中,每个窗体都有自己

    2024年02月02日
    浏览(24)
  • [游戏开发][Unity] Xlua与C#互相调用规则

    静态方法无需获取类对象,获取到类直接执行 例1: 例2 调用非静态方法一定要获取到具体的C#类对象!!! 例1:获取单例对象并调用非静态方法,Singleton是单例的一种写法,网上源码很多 下面是Lua调用C#的代码,我这是模拟Xlua的工程,以类的方式实现交互 看Log日志发现:

    2024年02月07日
    浏览(59)
  • C#开发DLL,CAPL调用(CAPL>> .NET DLL)

    ret为dll里函数返回的值。 在visual studio中建立。

    2024年02月08日
    浏览(31)
  • vue 打印html <iframe>标签(内容打印)超详细

    今天领导给了个需求,需要配合其他项目组给一个公共组件的npm进行,公共组件打印,打印操作由这个npm包来操作。(经过开会商讨,最后决定配置一个path路径,来展示页面,然后我负责在公共这里打印相应页面内容。)在这之初都是好着的,首先进行配置,这里只需要一个

    2024年02月15日
    浏览(42)
  • Python 直连打印机打印,可排版设置字体,附标签贴打印案例。

    前言:我用的是下面这款标签贴打印机,一开始试了好多打印方式,图片打印很糊,docx文件打印效果最好,但是每次打印会打开Word 影响效率,PDF也会打开PDF软件,打印效果略差于docx文件,TXT文件又不能设置字体,找了好久,结合几个文章得到了以下几乎完美的打印方式,可

    2024年02月08日
    浏览(27)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包