private void button1_Click(object sender, EventArgs e) { PrintLab.OpenPort(255); //打开打印机端口 PrintLab.PTK_ClearBuffer(); //清空缓冲区 PrintLab.PTK_SetPrintSpeed(4); //设置打印速度 PrintLab.PTK_SetDarkness(10); //设置打印黑度 PrintLab.PTK_SetLabelHeight(600, 16, 0, false); //设置标签的高度和定位间隙\黑线\穿孔的高度 PrintLab.PTK_SetLabelWidth(800); //设置标签的宽度 for (int i = 1; i <= 1; i++) { // 画矩形 PrintLab.PTK_DrawRectangle(58, 15, 3, 558, 312); // 打印PCX图片 方式一 PrintLab.PTK_PcxGraphicsDel("PCX"); PrintLab.PTK_PcxGraphicsDownload("PCX", "logo.pcx"); PrintLab.PTK_DrawPcxGraphics(80, 20, "PCX"); // 打印PCX图片 方式二 // PTK_PrintPCX(80,30,pchar('logo.pcx')); // 打印一个条码; PrintLab.PTK_DrawBarcode(300, 23, 0, "1", 2, 2, 50, 'B', "123456789"); // 画表格分割线 PrintLab.PTK_DrawLineOr(58, 100, 500, 3); // 打印一行TrueTypeFont文字; PrintLab.PTK_DrawTextTrueTypeW(80, 120, 40, 0, "Arial", 1, 400, false, false, false, "A1", "TrueTypeFont"); // 打印一行文本文字(内置字体或软字体); PrintLab.PTK_DrawText(80, 168, 0, 3, 1, 1, 'N', "Internal Soft Font"); // 打印PDF417码 PrintLab.PTK_DrawBar2D_Pdf417(80, 210, 400, 300, 0, 0, 3, 7, 10, 2, 0, 0, "123456789");//PDF417码 // 打印QR码 PrintLab.PTK_DrawBar2D_QR(420, 120, 180, 180, 0, 3, 2, 0, 0, "Postek Electronics Co., Ltd."); // 打印一行TrueTypeFont文字旋转; PrintLab.PTK_DrawTextTrueTypeW(520, 102, 22, 0, "Arial", 2, 400, false, false, false, "A2", "www.postek.com.cn"); PrintLab.PTK_DrawTextTrueTypeW(80, 260, 19, 0, "Arial", 1, 700, false, false, false, "A3", "Use different ID_NAME for different Truetype font objects"); // 命令打印机执行打印工作 PrintLab.PTK_PrintLabel(1, 1); } PrintLab.ClosePort();//关闭打印机端口 }
public static void PrintLabel(DataTable dt, int count) { PrintLab.OpenPort("POSTEK TX2r");//打开打印机端口 uint copynumber = Convert.ToUInt16(count); string eqNo = ""; string eqName = ""; string buyDate = ""; string depart = ""; for (int i = 0; i < dt.Rows.Count; i++) { PrintLab.PTK_ClearBuffer(); //清空缓冲区 PrintLab.PTK_SetPrintSpeed(4); //设置打印速度 PrintLab.PTK_SetDarkness(10); //设置打印黑度 PrintLab.PTK_SetLabelHeight(320, 16, 0, false); //设置标签的高度和定位间隙\黑线\穿孔的高度 PrintLab.PTK_SetLabelWidth(560); //设置标签的宽度 eqNo = dt.Rows[i]["资产编码"].ToString(); eqName = dt.Rows[i]["资产名称"].ToString(); buyDate = dt.Rows[i]["取得日期"].ToString(); depart = dt.Rows[i]["使用部门"].ToString(); // 画矩形 PrintLab.PTK_DrawRectangle(8, 8, 10, 552, 312); // 画表格分割线 PrintLab.PTK_DrawLineOr(8, 88, 544, 5); PrintLab.PTK_DrawLineOr(8, 144, 544, 5); PrintLab.PTK_DrawLineOr(8, 200, 368, 5); PrintLab.PTK_DrawLineOr(8, 256, 368, 5); PrintLab.PTK_DrawLineOr(140, 88, 5, 224); PrintLab.PTK_DrawLineOr(376, 144, 5, 168); // 打印标签样式 //PrintLab.PTK_DrawTextTrueTypeW(120, 18, 40, 0, "Arial", 1, 400, false, false, false, "company", "深圳大学师范学院"); PrintLab.PTK_DrawTextTrueTypeW(20, 98, 30, 0, "宋体", 1, 400, false, false, false, "EqName", "资产名称"); PrintLab.PTK_DrawTextTrueTypeW(20, 154, 30, 0, "宋体", 1, 400, false, false, false, "EqNo", "资产编码"); PrintLab.PTK_DrawTextTrueTypeW(20, 210, 30, 0, "宋体", 1, 400, false, false, false, "BuyDate", "购置年月"); PrintLab.PTK_DrawTextTrueTypeW(20, 266, 30, 0, "宋体", 1, 400, false, false, false, "Depart", "使用部门"); PrintLab.PTK_DrawTextTrueTypeW(150, 98, 30, 0, "宋体", 1, 400, false, false, false, "sEqName", eqName); PrintLab.PTK_DrawTextTrueTypeW(150, 154, 30, 0, "宋体", 1, 400, false, false, false, "sEqNo", eqNo); PrintLab.PTK_DrawTextTrueTypeW(150, 210, 30, 0, "宋体", 1, 400, false, false, false, "sBuyDate", buyDate); PrintLab.PTK_DrawTextTrueTypeW(150, 266, 30, 0, "宋体", 1, 400, false, false, false, "sDepart", depart); // 打印QR码 PrintLab.PTK_DrawBar2D_QR(400, 180, 180, 180, 0, 5, 2, 0, 0, eqNo); // 打印PCX图片 方式一 PrintLab.PTK_PcxGraphicsDel("PCX"); PrintLab.PTK_PcxGraphicsDownload("PCX", "logo.pcx"); PrintLab.PTK_DrawPcxGraphics(18, 20, "PCX"); // 命令打印机执行打印工作 PrintLab.PTK_PrintLabel(1, copynumber); } PrintLab.ClosePort();//关闭打印机端口 }