PPLB条码打印
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;//This is about DllImport. namespace VCsharp_2005
{
public partial class Form1 : Form
{
const uint IMAGE_BITMAP = 0;
const uint LR_LOADFROMFILE = 16;
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
static extern IntPtr LoadImage(IntPtr hinst, string lpszName, uint uType,
int cxDesired, int cyDesired, uint fuLoad);
[DllImport("Gdi32.dll", SetLastError = true, CharSet = CharSet.Auto)]
static extern int DeleteObject(IntPtr ho);
const string szSavePath = "C:\\Argox";
const string szSaveFile = "C:\\Argox\\PPLB_Example.Prn";
const string sznop1 = "nop_front\r\n";
const string sznop2 = "nop_middle\r\n";
[DllImport("Winpplb.dll")]
private static extern int B_Bar2d_Maxi(int x, int y, int cl, int cc, int pc, string data);
[DllImport("Winpplb.dll")]
private static extern int B_Bar2d_PDF417(int x, int y, int w, int v, int s, int c, int px,
int py, int r, int l, int t, int o, string data);
[DllImport("Winpplb.dll")]
private static extern int B_Bar2d_PDF417_N(int x, int y, int w, string para, string data);
[DllImport("Winpplb.dll")]
private static extern void B_ClosePrn();
[DllImport("Winpplb.dll")]
private static extern int B_CreatePrn(int selection, string filename);
[DllImport("Winpplb.dll")]
private static extern int B_Del_Form(string formname);
[DllImport("Winpplb.dll")]
private static extern int B_Del_Pcx(string pcxname);
[DllImport("Winpplb.dll")]
private static extern int B_Draw_Box(int x, int y, int thickness, int hor_dots,
int ver_dots);
[DllImport("Winpplb.dll")]
private static extern int B_Draw_Line(char mode, int x, int y, int hor_dots, int ver_dots);
[DllImport("Winpplb.dll")]
private static extern int B_Error_Reporting(char option);
[DllImport("Winpplb.dll")]
private static extern IntPtr B_Get_DLL_Version(int nShowMessage);
[DllImport("Winpplb.dll")]
private static extern int B_Get_DLL_VersionA(int nShowMessage);
[DllImport("Winpplb.dll")]
private static extern int B_Get_Graphic_ColorBMP(int x, int y, string filename);
[DllImport("Winpplb.dll")]
private static extern int B_Get_Graphic_ColorBMPEx(int x, int y, int nWidth, int nHeight,
int rotate, string id_name, string filename);
[DllImport("Winpplb.dll")]
private static extern int B_Get_Graphic_ColorBMP_HBitmap(int x, int y, int nWidth, int nHeight,
int rotate, string id_name, IntPtr hbm);
[DllImport("Winpplb.dll")]
private static extern int B_Get_Pcx(int x, int y, string filename);
[DllImport("Winpplb.dll")]
private static extern int B_Initial_Setting(int Type, string Source);
[DllImport("Winpplb.dll")]
private static extern int B_WriteData(int IsImmediate, byte[] pbuf, int length);
[DllImport("Winpplb.dll")]
private static extern int B_ReadData(byte[] pbuf, int length, int dwTimeoutms);
[DllImport("Winpplb.dll")]
private static extern int B_Load_Pcx(int x, int y, string pcxname);
[DllImport("Winpplb.dll")]
private static extern int B_Open_ChineseFont(string path);
[DllImport("Winpplb.dll")]
private static extern int B_Print_Form(int labset, int copies, string form_out, string var);
[DllImport("Winpplb.dll")]
private static extern int B_Print_MCopy(int labset, int copies);
[DllImport("Winpplb.dll")]
private static extern int B_Print_Out(int labset);
[DllImport("Winpplb.dll")]
private static extern int B_Prn_Barcode(int x, int y, int ori, string type, int narrow,
int width, int height, char human, string data);
[DllImport("Winpplb.dll")]
private static extern void B_Prn_Configuration();
[DllImport("Winpplb.dll")]
private static extern int B_Prn_Text(int x, int y, int ori, int font, int hor_factor,
int ver_factor, char mode, string data);
[DllImport("Winpplb.dll")]
private static extern int B_Prn_Text_Chinese(int x, int y, int fonttype, string id_name,
string data);
[DllImport("Winpplb.dll")]
private static extern int B_Prn_Text_TrueType(int x, int y, int FSize, string FType,
int Fspin, int FWeight, int FItalic, int FUnline, int FStrikeOut, string id_name,
string data);
[DllImport("Winpplb.dll")]
private static extern int B_Prn_Text_TrueType_W(int x, int y, int FHeight, int FWidth,
string FType, int Fspin, int FWeight, int FItalic, int FUnline, int FStrikeOut,
string id_name, string data);
[DllImport("Winpplb.dll")]
private static extern int B_Select_Option(int option);
[DllImport("Winpplb.dll")]
private static extern int B_Select_Option2(int option, int p);
[DllImport("Winpplb.dll")]
private static extern int B_Select_Symbol(int num_bit, int symbol, int country);
[DllImport("Winpplb.dll")]
private static extern int B_Select_Symbol2(int num_bit, string csymbol, int country);
[DllImport("Winpplb.dll")]
private static extern int B_Set_Backfeed(char option);
[DllImport("Winpplb.dll")]
private static extern int B_Set_BMPSave(int nSave, string strBMPFName);
[DllImport("Winpplb.dll")]
private static extern int B_Set_Darkness(int darkness);
[DllImport("Winpplb.dll")]
private static extern int B_Set_DebugDialog(int nEnable);
[DllImport("Winpplb.dll")]
private static extern int B_Set_Direction(char direction);
[DllImport("Winpplb.dll")]
private static extern int B_Set_Form(string formfile);
[DllImport("Winpplb.dll")]
private static extern int B_Set_Labgap(int lablength, int gaplength);
[DllImport("Winpplb.dll")]
private static extern int B_Set_Labwidth(int labwidth);
[DllImport("Winpplb.dll")]
private static extern int B_Set_Originpoint(int hor, int ver);
[DllImport("Winpplb.dll")]
private static extern int B_Set_Prncomport(int baud, char parity, int data, int stop);
[DllImport("Winpplb.dll")]
private static extern int B_Set_Prncomport_PC(int nBaudRate, int nByteSize, int nParity,
int nStopBits, int nDsr, int nCts, int nXonXoff);
[DllImport("Winpplb.dll")]
private static extern int B_Set_Speed(int speed);
[DllImport("Winpplb.dll")]
private static extern int B_Set_ProcessDlg(int nShow);
[DllImport("Winpplb.dll")]
private static extern int B_GetUSBBufferLen();
[DllImport("Winpplb.dll")]
private static extern int B_EnumUSB(byte[] buf);
[DllImport("Winpplb.dll")]
private static extern int B_CreateUSBPort(int nPort);
[DllImport("Winpplb.dll")]
private static extern int B_ResetPrinter();
[DllImport("Winpplb.dll")]
private static extern int B_GetPrinterResponse(byte[] buf, int nMax);
[DllImport("Winpplb.dll")]
private static extern int B_TFeedMode(int nMode);
[DllImport("Winpplb.dll")]
private static extern int B_TFeedTest();
[DllImport("Winpplb.dll")]
private static extern int B_CreatePort(int nPortType, int nPort, string filename);
[DllImport("Winpplb.dll")]
private static extern int B_Execute_Form(string form_out, string var);
[DllImport("Winpplb.dll")]
private static extern int B_Bar2d_QR(int x, int y, int model, int scl, char error,
char dinput, int c, int d, int p, string data);
[DllImport("Winpplb.dll")]
private static extern int B_GetNetPrinterBufferLen();
[DllImport("Winpplb.dll")]
private static extern int B_EnumNetPrinter(byte[] buf);
[DllImport("Winpplb.dll")]
private static extern int B_CreateNetPort(int nPort);
[DllImport("Winpplb.dll")]
private static extern int B_Prn_Text_TrueType_Uni(int x, int y, int FSize, string FType,
int Fspin, int FWeight, int FItalic, int FUnline, int FStrikeOut, string id_name,
byte[] data, int format);
[DllImport("Winpplb.dll")]
private static extern int B_Prn_Text_TrueType_UniB(int x, int y, int FSize, string FType,
int Fspin, int FWeight, int FItalic, int FUnline, int FStrikeOut, string id_name,
byte[] data, int format);
[DllImport("Winpplb.dll")]
private static extern int B_GetUSBDeviceInfo(int nPort, byte[] pDeviceName,
out int pDeviceNameLen, byte[] pDevicePath, out int pDevicePathLen);
[DllImport("Winpplb.dll")]
private static extern int B_Set_EncryptionKey(string encryptionKey);
[DllImport("Winpplb.dll")]
private static extern int B_Check_EncryptionKey(string decodeKey, string encryptionKey,
int dwTimeoutms); public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
//Test code start
// open port.
int nLen, ret, sw;
byte[] pbuf = new byte[128];
string strmsg;
IntPtr ver;
System.Text.Encoding encAscII = System.Text.Encoding.ASCII;
System.Text.Encoding encUnicode = System.Text.Encoding.Unicode; // dll version.
ver = B_Get_DLL_Version(0); // search port.
nLen = B_GetUSBBufferLen() + 1;
strmsg = "DLL ";
strmsg += Marshal.PtrToStringAnsi(ver);
strmsg += "\r\n";
if (nLen > 1)
{
byte[] buf1, buf2;
int len1 = 128, len2 = 128;
buf1 = new byte[len1];
buf2 = new byte[len2];
B_EnumUSB(pbuf);
B_GetUSBDeviceInfo(1, buf1, out len1, buf2, out len2);
sw = 1;
if (1 == sw)
{
ret = B_CreatePrn(12, encAscII.GetString(buf2, 0, len2));// open usb.
}
else
{
ret = B_CreateUSBPort(1);// must call B_GetUSBBufferLen() function fisrt.
}
if (0 != ret) {
strmsg += "Open USB fail!";
}
else {
strmsg += "Open USB:\r\nDevice name: ";
strmsg += encAscII.GetString(buf1, 0, len1);
strmsg += "\r\nDevice path: ";
strmsg += encAscII.GetString(buf2, 0, len2);
//sw = 2;
if (2 == sw)
{
//Immediate Error Report.
B_WriteData(1, encAscII.GetBytes("^ee\r\n"), 5);//^ee
ret = B_ReadData(pbuf, 4, 1000);
}
}
}
else
{
System.IO.Directory.CreateDirectory(szSavePath);
ret = B_CreatePrn(0, szSaveFile);// open file.
strmsg += "Open ";
strmsg += szSaveFile;
if (0 != ret) {
strmsg += " file fail!";
}
else {
strmsg += " file succeed!";
}
}
MessageBox.Show(strmsg);
if (0 != ret)
return; // sample setting.
B_Set_DebugDialog(1);
B_Set_Originpoint(0,0);
B_Select_Option(2);
B_Set_Darkness(8);
B_Del_Pcx("*");// delete all picture.
B_WriteData(0, encAscII.GetBytes(sznop2), sznop2.Length);
B_WriteData(1, encAscII.GetBytes(sznop1), sznop1.Length); //draw box.
B_Draw_Box(20, 20, 4, 760, 560);
B_Draw_Line('O', 400, 20, 4, 540); //print text, true type text.
B_Prn_Text(30, 40, 0, 2, 1, 1, 'N', "PPLB Lib Example");
B_Prn_Text_TrueType(30,100,30,"Arial",1,400,0,0,0,"AA","TrueType Font");//save in printer.
B_Prn_Text_TrueType_W(30,160,20,20,"Times New Roman",1,400,0,0,0,"AB","TT_W: 多字元測試");
B_Prn_Text_TrueType_Uni(30,220,30,"Times New Roman",1,400,0,0,0,"AC",Encoding.Unicode.GetBytes("TT_Uni: 多字元測試"),1);//UTF-16
encUnicode.GetBytes("\xFEFF", 0, 1, pbuf, 0);//UTF-16.//pbuf[0]=0xFF,pbuf[1]=0xFE;
encUnicode.GetBytes("TT_UniB: 多字元測試", 0, 14, pbuf, 2);//copy mutil byte.
encUnicode.GetBytes("\x0000", 0, 1, pbuf, 30);//null.//pbuf[30]=0x00,pbuf[31]=0x00;
B_Prn_Text_TrueType_UniB(30,280,30,"Times New Roman",1,400,0,0,0,"AD",pbuf,0);//Byte Order Mark. //barcode.
B_Prn_Barcode(420, 100, 0, "3", 2, 3, 40, 'B', "1234<+1>");//have a counter
B_Bar2d_QR(420, 200, 1, 3, 'M', 'A', 0, 0, 0, "QR CODE"); //picture.
B_Get_Graphic_ColorBMP(420, 280, "bb.bmp");// Color bmp file.
B_Get_Graphic_ColorBMPEx(420, 320, 200, 150, 2, "bb1", "bb.bmp");//180 angle.
IntPtr himage = LoadImage(IntPtr.Zero, "bb.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
B_Get_Graphic_ColorBMP_HBitmap(630, 280, 250, 80, 1, "bb2", himage);//90 angle.
if (IntPtr.Zero != himage)
DeleteObject(himage); // output.
B_Print_Out(2);// copy 2. // close port.
B_ClosePrn();
} private void button2_Click(object sender, EventArgs e)
{
//PPLBDLL Test code start
//B_CreatePrn(0, null); /*
int B_CreatePrn(int selection, LPCTSTR filename);
參數:
selection;
選擇輸出埠或檔案。
0 -> print to file.
1 -> lpt1, 2 -> lpt2, 3 -> lpt3
4 -> com1, 5 -> com2, 6 -> com3
10 -> pipe, 11 -> USBXXX, 12 -> USB
13 -> LAN Client(TCP/IP)
filename;
當 selection 是 0 時,資料則輸出至檔案,filename 為檔案名稱,可含路徑。
當 selection 是 10 時,filename 為輸出路徑或機碼(裝置路徑)。
當 selection 是 11 時,filename 指的是想開啟的USB之index, index由1開始;
當 selection 是 12 時,filename 指的是想開啟的USB機碼(裝置路徑),
和nPort = 10的使用方法一樣
當 selection 內容是 13 時, filename 指的是想開啟的IP Address, 使用TCP/IP去開啟;
預設的port值為9100, 若要指定port值, 如80, 則在IPAddress後加上字串":80".
*
int B_CreateUSBPort(int nPort);
參數:
nPort;
USB 傳輸埠 ; nPort由1開始.
*/
// USB Port Open
int nUSBDataLen;
byte[] pbuf;
nUSBDataLen = B_GetUSBBufferLen()+1;
pbuf = new byte[nUSBDataLen];
B_EnumUSB(pbuf);
B_CreateUSBPort(1); // Open com3
//B_CreatePort(1, 3, null);
//B_Set_Darkness(8);
//B_Select_Option(1);
//B_Set_Labgap(50,24);
//B_Set_Labwidth(816);
//B_Set_Speed(2);
//B_Error_Reporting('S'); B_Prn_Text(100, 200, 0, 3, 1, 1, 'N', "FONT 3"); //Get a text string.
// B_Prn_Text(200,10,1,3,1,1,'N',"Text 3<+1>");
B_Prn_Barcode(20, 20, 0, "1", 3, 3, 75, 'B', "079-305"); //Get a bar code.
//Get a PDF-417 2D bar code.
//B_Bar2d_PDF417(50, 150, 400, 300, 0, 0, 3, 7, 10, 2, 0, 0, "ARGOXINFO");
//Get a Maxi Code 2D bar code.
B_Bar2d_Maxi(400, 10, 300, 400, 93065, "This MaxiCode");
B_Draw_Line('E', 380, 200, 100, 10); //Line Draw by Exclusive or operation.
//B_Draw_Line('O', 400, 180, 10, 100); //Line draw by or operation.
//B_Draw_Line('W', 380, 220, 100, 10); //Draw white line.
//B_Draw_Line('E', 450, 180, 20, 110); //Line Draw by Exclusive or operation.
//B_Draw_Box(0, 0, 5, 815, 300); //Draw a box.
// B_Get_Pcx(50,55,"phone.pcx"); //Print Graphics of .PCX.
//B_Get_Pcx(400,0,"test1.pcx");
B_Prn_Text_TrueType(450, 20, 40, "Times New Roman", 1, 400, 0, 0, 0, "AA", "Library Test");
// Get a truetype text
//B_Prn_Text_TrueType(30,50,20,"Arial",4,400,0,0,0,"AB","TrueType Font");
B_Print_Out(1);
B_ClosePrn();
//PPLBDLL Test code end
}
}
}
PPLB条码打印的更多相关文章
- AX 条码打印
AX 条码打印集成在BarCode类及其之类barcode*. 由子类的defaultFont方法指定字体属性. eg, BarcodeCode39 指定条码字体"BC C39 3 to 1 ...
- BarTender SDK 实现调用模板条码打印
Demo:MyZebraPrint 基于BatTender .Net SDK 实现调用模板进行条码打印 有需要的朋友可以拿去研究下 在已经安装了BatTender10.1的电脑里测试通过. 下载地址: ...
- PowerBuilder -- 条码打印
# 使用ocx控件 使用微软的MSBCODE9.OCX,但是注册老不成功,需要安装office之后才能注册成功,不知道有没有好的处理方法?? # 使用字体 字体下载:http://download.c ...
- smartforms 条码打印
转自:http://blog.csdn.net/zhongguomao/article/details/6759642 SAP 条码打印有 新旧 两种技术方法:1.传统的(旧):将数据发送到打印机上, ...
- C#.Net集成Bartender条码打印,VS调试运行可以打印,发布到IIS运行打印报错
C#.Net集成Bartender条码打印,VS调试运行可以打印,发布到IIS运行打印报错 问题原因: 问题出现在iis账户权限. 解决方法: iis默认是用network service这个账户去执 ...
- RDLC系列之七 条码打印
参考: C# 条码标签打印程序,RDLC报表动态显示多条码标签的方法 http://www.cnblogs.com/vice/p/4105898.html 我做的思路是:不使用数据库存储image的b ...
- ABAP-smartform-一页3列的条码打印
1.自建barcode: se73->System bar code->change->create->new input the name of the bar code y ...
- WinForm条码打印
在这篇博客中,我曾经介绍了如何实现条形码的生成(生成jpg格式的图片),这篇博客借用上面生成的条码,能够实现条形码的打印功能. 出于批量打印操作的方便以及操作体验考虑,我选择了WinForm.功能很简 ...
- ZPL条码打印类
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.I ...
随机推荐
- 【小白成长撸】--Fibonacci
/*程序的版权和版本声明部分: *Copyright(c) 2016,电子科技大学本科生 *All rights reserved. *文件名:Fibonacci *程序作用:计算菲薄拉稀数列 *作者 ...
- (三)、LNMP的搭建,并制作rpm包
中小型规模网站集群架构:yum仓库搭建 : 矮哥linux运维群:93324526 编译的三条命令的规则 ./configure 就是在本地创建了一个Makefile文件 (也就是指定一下各种配置参数 ...
- jq分页插件,支持动态,静态分页的插件,简单易用。
工作中经常要用到分页功能.为了方便封装了一个比较通用的分页插件开源出来了,简单易用. 官网:https://cwlch.github.io/Ch_Paging 下载地址:https://github. ...
- css预处理器less和scss之less介绍(一)
第一次发的标题有误,重发一遍,抱歉了 一.less基础语法 1.声明变量:@变量名:变量值 使用变量:@变量名 例如 @color : #ff0000; @length : 100px; #div1{ ...
- 【1414软工助教】团队作业2——需求分析&原型设计 得分榜
题目 团队作业2--需求分析&原型设计 作业提交情况情况 本次作业所有团队都按时提交作业. 往期成绩 个人作业1:四则运算控制台 结对项目1:GUI 个人作业2:案例分析 结对项目2:单元测试 ...
- 预防黑客入侵 防黑必学的cmd命令vs网络安全
这些命令又可*********三类:网络检测(如ping).网络连接(如telnet)和网络配置(如netsh).前面两种相对简单,本文只介绍两个网络配置工具.自带的关于网络的命令行工具很多,比如大家 ...
- JAVA课程设计猜数游戏 个人
1.团队课程设计博客链接 https://i.cnblogs.com/EditPosts.aspx?postid=7067843&update=1 2.个人负责模块说明 输入用户ID 2.主要 ...
- 时间效率:整数中1出现的次数(从1到n整数中1出现的次数)
求出1~13的整数中1出现的次数,并算出100~1300的整数中1出现的次数?为此他特别数了一下1~13中包含1的数字有1.10.11.12.13因此共出现6次,但是对于后面问题他就没辙了.ACMer ...
- JavaScript配合button.onclick()使用总结
Html加载顺序是从上往下加载,如果script中含有引用js脚本,则应该将此script放在head标签里面,这样可是保证此页面都可以引用js脚本内容.如果想在script中设置button.onc ...
- Java中数组的概念
1.什么是二维数组?有几种表达方式?分别是什么? 答:多维数组即数组的数组,即数组的元素也是数组. 例:int[] [] a = {{1},{1,2},{1,2,3}}; 有三种方式 1).int [ ...