C#调用CODESOFT标签打印

1、创建标签模板

2、在C#项目中引用CODESOFT插件

在项目中引用软件对应插件,路径见下图 "Lppx2.tlb"

 

 

添加成功后,在引用中会出现:

 

3、方法函数如下:

        private void Label_Print(Machine_Info machine_information, string labPath)
        {
            try
            {
                labApp = new LabelManager2.ApplicationClass();
                labApp.Documents.Open(labPath, false);
                filePath = System.Environment.CurrentDirectory + @"\log\" + DateTime.Now.Year + DateTime.Now.Month + DateTime.Now.Day + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second + ".bmp";
                doc = labApp.ActiveDocument;
                doc.Variables.FormVariables.Item("GEELY零件号").Value = machine_information.GeelyPN;
                doc.Variables.FormVariables.Item("H/W").Value = machine_information.HW;
                //doc.Variables.FormVariables.Item("LabelSN").Value = machine_information.PN;
                doc.Variables.FormVariables.Item("P/N").Value = machine_information.AutolinkPN;
                doc.Variables.FormVariables.Item("S/W").Value = machine_information.SW;
                doc.Variables.FormVariables.Item("LabelSN").Value = machine_information.LabelSN;
                doc.Variables.FormVariables.Item("产品型号").Value = machine_information.ProType;
                doc.Variables.FormVariables.Item("供应商代码").Value = machine_information.SupplierCode;
                doc.Variables.FormVariables.Item("变量17").Value = machine_information.IHUID;
                doc.Variables.FormVariables.Item("变量18").Value = machine_information.XDSN;
                doc.Variables.FormVariables.Item("批次号").Value = machine_information.BatchNumber;
                doc.Variables.FormVariables.Item("模糊批次").Value = machine_information.Date;
                doc.Variables.FormVariables.Item("零件名称").Value = machine_information.ComponentsNumber;
                string str = doc.CopyImageToFile(8, "BMP", 0, 100, filePath);
                //PictureBox pictureBox = new PictureBox();
                //pictureBox.Load(filePath);
                pictureBox.Load(filePath);

                doc.PrintDocument(1);

            }
            catch (Exception ex)
            {
                MessageBox.Show("error: " + ex.Message);
            }
            finally
            {
                labApp.Documents.CloseAll(true);
                labApp.Quit();
                labApp = null;
                doc = null;

            }
        }

 

posted @ 2023-01-18 15:53  Charlie9527  阅读(1788)  评论(2编辑  收藏  举报