Android 精臣打印机, 标签打印 插件
详细内容
Android 精臣 标签 打印插件
1. 精臣打印机,连接设置.
- 必须要打开手机蓝牙,并且需要先配对打印机蓝牙成功后,才能连接打印机。
2. 在需要使用的页面中引入插件
复制代码const plug=uni.requireNativePlugin("Html5app-Jcprinter");
3. 插件方法介绍
方法名 | 说明 |
---|---|
getAllPrinter | 获取所有已配的打印机设备 |
connectPrinter | 连接打印机 |
state | 打印机连接状态 |
disconnect | 断开打印机 |
printer | 打印标签 |
4. getAllPrinter | 获取所有已配的打印机设备
复制代码plug.getAllPrinter({name:"B11"},ret=>{
JSON.stringify(ret);
});
- 参数说明: name => 打印机设备前缀名称,可以过滤掉其他不需要的设置.
- 返回结果, 数组
复制代码{
"list":[
{
"address":"DC:0D:30:3D:08:DC",
"name":"B11-90487050"
}
],
"code":"0"
}
5. connectPrinter | 连接打印机
复制代码 plug.connectPrinter({name:"B11-90487050"},ret=>{
});
- 参数说明:name => 精臣打印机型号名称
- 返回结果
复制代码{"msg":"正在连接打印机...","code":1}
{"msg":"打印机已连接","code":2}
{"msg":"打印机连接超时,请检查后再试","code":3}
{"msg":"打印机名称不能为空","code":-1}
{"msg":"打印机连接失败","code":-2}
6. state | 打印机连接状态
复制代码plug.state(ret=>{
});
- 返回结果
复制代码{"msg":"打印机已连接","code":0}
{"msg":"打印机已断开","code":-1}
7. disconnect | 断开打印机
复制代码plug.disconnect(ret=>{
});
- 返回结果
复制代码{"msg":"打印机已断开","code":0}
8. printer | 打印标签
复制代码plug.printer({data:""},ret=>{
});
- 参数说明:data => 是一个打印数据的数组.
打印示例
- 打印文字
复制代码 //添加文字
line={};
line.text="HTML5+混合APP开发社区"; //文字内容
line.rotation=0; //旋转角度:0/90/180/270
line.width=50; //文本的宽度 单位:mm
line.height=80; //文本的高度 单位:mm
line.top=5; //距离顶部的距离 单位:mm
line.left=0; //距离左边的距离 单位:mm
line.fontHeight=3; //文字的大小高度设置
line.fontStyle=0; //文字的样式:0=>正常,1=>粗体,2=>斜体,3=>粗斜体,4=>下划线,8=>删除线
line.align="left"; // left=>靠左,center=>居中,right=>靠右
data.push(line); //每添加一个,代表一行字
- 打印图片
复制代码 //添加图片
line={};
line.image="http://www.html5-app.com/gprinter.png"; //支持网络图片和本地路径图片
line.top=12; //距离顶部的距离 单位:mm
line.left=5; //距离左边的距离 单位:mm
line.width=15; //图片宽度 单位:mm
line.height=15; //图片高度 单位:mm
line.rotation=0; //旋转角度:0/90/180/270
data.push(line);
- 打印一维码/条型码
复制代码 //添加条型码
line={};
line.barcode="2019563352660"; //条型码内容
line.top=40; //距离顶部的距离 单位:mm
line.left=0; //距离左边的距离 单位:mm
line.type="CODE128"; 条型码类型
line.height=10; //条型码高度 单位:mm
line.width=25; //条型码宽度 单位:mm
line.textHeight=3; //可见文字大小高度
line.rotation=0; //旋转角度:0/90/180/270
data.push(line);
- 打印二维码
复制代码 line={};
line.qrcode="ddddddd"; //二维码内容
line.top=50; //距离顶部的距离 单位:mm
line.left=10; //距离左边的距离 单位:mm
line.width=15; //二维码大小 单位:mm
line.rotation=0; //旋转角度:0/90/180/270
data.push(line);
- 其他画线
复制代码 line={}; //画一个矩形
line.drawRectangle={left:10,top:10,width:20,height:3,lineWidth:1};
data.push(line);
lineWidth => 边线大小
line={}; //画一个带有圆角的矩形
line.drawRoundRectangle={left:0,top:15,width:20,height:3,cornerWidth:1,cornerHeight:1,lineWidth:1};
data.push(line);
cornerWidth =>圆角宽度大小, cornerHeight =>圆角高度大小
line={}; //画一个圆形
line.drawEllipse={left:0,top:18,width:10,height:10,lineWidth:1};
data.push(line);
line={}; //画直线/斜线, 两个坐标点,决定一条直线
line.drawLine={x1:0,y1:22,x2:35,y2:18,lineWidth:1};
data.push(line);
line={}; //填充画一个矩形
line.fillRectangle={left:10,top:10,width:20,height:3};
data.push(line);
line={}; //填充,以指定的线宽,绘制圆角矩形框
line.fillRoundRectangle={left:0,top:15,width:20,height:3,cornerWidth:1,cornerHeight:1};
data.push(line);
line={}; //填充 以指定的线宽,绘制圆
line.fillEllipse={left:0,top:18,width:10,height:10};
data.push(line);
line={}; //填充 打印填充圆形
line.fillCircle={left:0,top:18,radius:10};
data.push(line);
加载更多