阅读(1486) (2)

printLabel

2022-06-21 15:52:34 更新

打印标签(TSC模式打印,确保打印机处于标签模式)

printLabel({params}, callback(ret, err))

params

xh:

  • 类型:数字型
  • 描述:(可选项)指定打印机0-3。
  • 默认值:0

rows:

  • 类型:数组
  • 描述:(必输项)打印数据。

[{
    lineType: 'size',//设置标签尺寸,按照实际尺寸设置
    width : 80,
    height : 72
},{
    lineType: 'gap',   //设置标签间隙,按照实际尺寸设置
    data : 0    //如果为无间隙纸则设置为0
},{
    lineType: 'direction',   //设置打印方向
    direction : 'backward',   //backward|forward
    mirror : 'normal'         //normal|mirror
},{
    lineType: 'reference',   /设置原点坐标
    x : 0 ,
    y : 0
},{
    lineType: 'tear',   //撕纸模式开启
    data : true
},{
    lineType: 'cls'  // 清除打印缓冲区
},{
    lineType: 'text',  //绘制简体中文
    x : 20 ,
    y : 20,
    rotation : 0, // 0|90|180|270
    xscal : 1,    //1~10
    yscal : 1,     //1~10
    data : '要打印的文字'
},{
    lineType: 'image',  //绘制图片
    x : 20,
    y : 50,
    data : 'widget://image/huibo_logo.png' //支持fs:// widget://
},{
    lineType: 'qrcode',  绘制qrcode
    x : 250 ,
    y : 80 ,
    level : 'L',  //L|M|H|Q
    cellwith : 5,
    rotation : 0, // 0|90|180|270
    data : '要打印的二维码内容'
},{
    lineType: 'code128',  //绘制一维条码
    x : 250 ,
    y : 80 ,
    height : 100,
    rotation : 0, // 0|90|180|270
    data : '123456789'
},{
    lineType: 'bar',  //画线
    x : 0 ,
    y : 0 ,
    width : 0
    height : 0
}]

openBox:

  • 类型:布尔型
  • 描述:(可选项)是否打开钱箱。
  • 默认值:true

callback(ret, err)

ret:

  • 类型:JSON对象
  • 内部字段:

{
    status: true   //布尔型;true||false
}

err:

  • 类型:JSON对象
  • 内部字段:

{
    msg:""
}

示例代码

var obj = api.require('xGprinterPlus');
demo.printLabel({
    rows : [{
        lineType : 'size',
        width : 80,
        height : 72
    },{
        lineType : 'gap',
        data : 0
    },{
        lineType : 'cls'
    },{
        lineType : 'gap',
        data : 0
    },{// 左边框
        lineType : 'bar',
        x : 16,
        y :  0,
        width : 4,
        height : 556
    },{// 上边框
        lineType : 'bar',
        x : 16,
        y :  0,
        width : 608,
        height : 8
    },{// 右边框
        lineType : 'bar',
        x : 624,
        y :  0,
        width : 4,
        height : 556
    },{// 下边框
        lineType : 'bar',
        x : 16,
        y :  556,
        width : 608,
        height : 4
    },{// 图片单元格竖线
        lineType : 'bar',
        x : 16 + 130,
        y :  0,
        width : 2,
        height : 106
    },{//绘制图片
        lineType : 'image',
        x : 16 + 8,
        y :  8,
        data : 'widget://image/huibo_logo.png'
    },{//绘制文本
        lineType : 'text',
        x : 16 + 8,
        y :  8,
        rotation : 0,
        xscal : 1,
        yscal : 1,
        data : '青岛汇博通商贸有限公司'
    },{// 图片单元格横线
        lineType : 'bar',
        x : 16 + 130,
        y :  56,
        width : 640 - 130 - 16 - 16,
        height : 2
    },{// 二维码旁边竖线
        lineType : 'bar',
        x : 16 + 320,
        y :  106,
        width : 2,
        height : 556 - 106
    },{// 横线
        lineType : 'bar',
        x : 16 ,
        y :  106,
        width : 608,
        height : 2
    },{//绘制文本
        lineType : 'text',
        x : 16 + 4,
        y :  106 + 2,
        rotation : 0,
        xscal : 1,
        yscal : 2,
        data : '捆包号:R103571234'
    },{//绘制文本
        lineType : 'text',
        x : 16 + 320 + 2,
        y :  106 + 2,
        rotation : 0,
        xscal : 1,
        yscal : 2,
        data : '钢厂资源号:ML123456789'
    },{// 横线
        lineType : 'bar',
        x : 16 + 320 + 2 ,
        y :  156,
        width : 608,
        height : 2
    },{//绘制code128
        lineType : 'code128',
        x : 16 + 16,
        y :  156 + 2,
        height : 48,
        rotation : 0,
        data : '1234567890'
    },{//绘制文本
        lineType : 'text',
        x : 16 + 320 + 2,
        y :  156 + 2,
        rotation : 0,
        xscal : 1,
        yscal : 2,
        data : '母卷号:P123456789'
    },{// 横线
        lineType : 'bar',
        x : 16 ,
        y :  206,
        width : 608,
        height : 2
    },{//绘制文本
        lineType : 'text',
        x : 16 + 4,
        y :  206 + 2,
        rotation : 0,
        xscal : 1,
        yscal : 2,
        data : '品名:冷轧卷'
    },{//绘制文本
        lineType : 'text',
        x : 16 + 320 + 2,
        y :  206 + 2,
        rotation : 0,
        xscal : 1,
        yscal : 2,
        data : '牌号:DC06'
    },{// 横线
        lineType : 'bar',
        x : 16 ,
        y :  256,
        width : 608,
        height : 2
    },{//绘制文本
        lineType : 'text',
        x : 16 + 4,
        y :  256 + 2,
        rotation : 0,
        xscal : 1,
        yscal : 2,
        data : '规格:1.2*1250*C'
    },{//绘制文本
        lineType : 'text',
        x : 16 + 320 + 2,
        y :  256 + 2,
        rotation : 0,
        xscal : 1,
        yscal : 2,
        data : '净重:10.5t'
    },{// 横线
        lineType : 'bar',
        x : 16 ,
        y :  306,
        width : 608,
        height : 2
    },{//绘制文本
        lineType : 'text',
        x : 16 + 4,
        y :  306 + 2,
        rotation : 0,
        xscal : 1,
        yscal : 2,
        data : '毛重:10.8t'
    },{//绘制文本
        lineType : 'text',
        x : 16 + 320 + 2,
        y :  306 + 2,
        rotation : 0,
        xscal : 1,
        yscal : 2,
        data : '件数:1'
    },{// 横线
        lineType : 'bar',
        x : 16 ,
        y :  356,
        width : 608,
        height : 2
    },{//绘制文本
        lineType : 'text',
        x : 16 + 4,
        y :  356 + 2,
        rotation : 0,
        xscal : 1,
        yscal : 2,
        data : '库区:原料区'
    },{//绘制qrcode
        lineType : 'qrcode',
        x : 16 + 320 + 2 + 100,
        y :  356 + 2 + 25,
        level : 'L',
        cellwith : 5,
        rotation : 0,
        data : '捆包号|钢厂资源号|母卷号|品名|牌号|规格|净重|毛重'
    },{// 横线
        lineType : 'bar',
        x : 16 ,
        y :  406,
        width : 320,
        height : 2
    },{//绘制文本
        lineType : 'text',
        x : 16 + 4,
        y :  406 + 2,
        rotation : 0,
        xscal : 1,
        yscal : 2,
        data : '库位:YC-02'
    },{// 横线
        lineType : 'bar',
        x : 16 ,
        y :  456,
        width : 320,
        height : 2
    },{//绘制文本
        lineType : 'text',
        x : 16 + 4,
        y :  456 + 2,
        rotation : 0,
        xscal : 1,
        yscal : 2,
        data : '收货单位:英大'
    },{// 横线
        lineType : 'bar',
        x : 16 ,
        y :  506,
        width : 320,
        height : 2
    },{//绘制文本
        lineType : 'text',
        x : 16 + 4,
        y :  506 + 2,
        rotation : 0,
        xscal : 1,
        yscal : 2,
        data : '日期:2016.06.12'
    }]
},function(ret, err){
    alert(JSON.stringify(ret)+"   "+ JSON.stringify(err));
});

可用性

Android系统

可提供的1.0.5及更高版本