codecamp

printData

打印数据

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

params

  • data:

  • 类型:数组
  • 描述:打印数据。

  [{
      rowtype: 'printText',                  //打印文字,文字宽度满一行自动换行排版
      text : '',                              //要打印的文字字符串
      size:,                                //字体大小
         isBole:'',                            //粗体
         isUnderLine:'',                         //下划线
  },{
      rowtype: 'lineWrap',                  //打印机走纸
      n : 3                                     //走纸行数
  },{
      rowtype: 'printTable',                  //打印表格
      colsText : "名称,数量,单价,金额",      //表头
      colsWidth:[10, 6, 6, 8],             //各列单元格宽度
      colsAlign:[1, 2, 2, 2],             //各列单元格对齐(0居左, 1居中, 2居右)
      dataArr:[                           //单元内容(数组)
          "商品A,6,12.00,72.00",
          "商品B,8,13.00,104.00"],
  },{
      rowtype : "setFontSize",            //设置字体大小, 对之后打印有影响,除非初始化
      size:24                               //字体大小
  },{
      rowtype : "setAlignment",            //设置对齐模式,对之后打印有影响,除非初始化
      alignment:1                           //对齐方式 0--居左 , 1--居中, 2--居右
  },{
      rowtype : 'printBitmap',            //打印图片
      image:'widget://res/test.jpg'        //图片bitmap对象(最大宽度384像素,超过无法打印) 支持widget:// fs://
  },{
      rowtype: 'printBarCode', //打印条形码
      text : '',              //条码数据
      symbology : 8,             //条码类型:0:UPC-A,1:UPC-E,2:JAN13(EAN13),3:JAN8(EAN8),4:CODE39,5:ITF,6:CODABAR,7:CODE93,8:CODE128
      height : 80,             //条码高度:取值1到255, 默认162
      width : 2,                //条码宽度:取值2至6, 默认2
      textposition : 2        //文字位置:0--不打印文字, 1--文字在条码上方, 2--文字在条码下方, 3--条码上下方均打印
  }]

callback(ret, err)

ret:

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

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

err:

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

{
    msg: ''
}

示例代码

var param = {data:[
                { 
                    rowtype : 'printText',
                    text:'Hello APICloud!',
                    size:18,
                    isBole:'false',
                    isUnderLine:'fasle'
                },{
                    rowtype : 'lineWrap',
                    n:1
                },{
                    rowtype : 'printTable',
                    colsText:"名称,数量,单价,金额",
                    colsWidth : [10, 6, 6, 8],
                    colsAlign : [1, 2, 2, 2],
                    dataArr:[
                        "商品A,6,12.00,72.00",
                        "商品B,8,13.00,104.00"],
                },{
                    rowtype : 'printText',
                    text:'------------------'
                },{
                    rowtype : "setFontSize",            
                    size:24                              
                },{
                    rowtype : "setAlignment",            
                    alignment:1                          
                },{ 
                    rowtype : 'printText',
                    text:'Hello APICloud!',
                },{
                    rowtype : 'printBitmap',            
                    image:'widget://res/test.jpg'
                },{
                    rowtype : 'printBarCode',
                    text:'20190630001',
                    symbology:8,
                    height:80,
                    width:2,
                    textposition:2
                },{
                    rowtype : 'lineWrap',
                    n:3
                }
            ]};


    sunmiV2Printer.printData(param,function(ret, err){
        alert(JSON.stringify(ret));
    });

可用性

Android系统

可提供的1.0.0及更高版本

printText
lineWrap
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

端API

设备访问

ipAddress

wifiSSID

smartConfigCheyw

无标题文章

前端框架

云API

开发工具

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }