xGprinter

来自于:开发者立即使用

connect printTest printMultipleText printImage getStatus

概述

xGprinter装了佳博官方2.1.4版SDK,可通过蓝牙、usb、网口连接打印机,并支持自定义数据打印。

connect

连接打印机

connect()

示例代码

  1. var gprinter = api.require('xGprinter');
  2. gprinter.connect();
  3. });

可用性

Android系统

可提供的1.0.0及更高版本

printTest

打印测试页

printTest()

示例代码

  1. var gprinter = api.require('xGprinter');
  2. gprinter.printTest();

可用性

Android系统

可提供的1.0.0及更高版本

printMultipleText

打印自定义数据(多行文本)

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

params

project:

  • 类型:数组
  • 描述:(必填项)打印联式名称。

title:

  • 类型:字符串
  • 描述:(必填项)票据抬头
  • 默认值:’’

rows:

  • 类型:数组
  • 描述:(必填项)票据每行内容及样式。
  • 示例:{text : ‘内容’, style : [0,0,0,0], align:’left|center|right’, lineHeight:60}
  • 说明: style 每个元素对应打印样式标志位,分别是:[是否加粗,是否倍高,是否倍宽,是否下划线] align 对齐方式,分别是:left 左对齐, center 居中对齐, right 右对齐 lineHeight 行间距

isSubject:

  • 类型:布尔
  • 描述:(必填项)是否需要打印联式名称。
  • 取值范围:true|false

示例代码

  1. var gprinter = api.require('xGprinter');
  2. gprinter.printMultipleText({
  3. title : '自定义数据',
  4. project : ['联1','联2'],
  5. rows : [{
  6. text : '内容1',
  7. style : [0,0,1,0,1], //不加粗,不倍高,倍宽,不采用下划线,使用
  8. align : 'center',
  9. lineHeight : 60,
  10. image : '图片base64编码' //当text为空时使用image
  11. }],
  12. isSubject : true
  13. });

可用性

Android系统

可提供的1.0.0及更高版本

printImage

打印自定义数据(打印图片)

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

params

base64:

  • 类型:字符串
  • 描述:(必填项)图片base64编码,注意去掉头信息。

示例代码

  1. var gprinter = api.require('xGprinter');
  2. gprinter.printImage({
  3. base64 : 'iVBORw0KGgoAAAANSUhEUgAAAMAAAADACAYAAABS3GwHAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAOxAAADsQBlSsOGw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KyhEUAAjRtVIQQQICRI1tAIIIDGjaoQAggQEiRraAQQQONGVQgBBAgJkjU0AgigcaMqhAAChATJGhoBBNC4URVCAAFCgmQNjQACaNyoCiGAACFBsoZGAAE0blSFEECAkCBZQyOAABo3qkIIIEBIkKyhEUAAjRtVIQQQICRI1tAIIIDGjaoQAggQEiRraAQQQONGVQgBBAgJkjU0AgigcaMqhAAChATJGhoBBNC4URVCAAFCgmQNjQACaNyoCiGAACFBsoZGAAE0blSFEECAkCBZQyOAABo3qkIIIEBIkKyhEUAAjRtVIQQQICRI1tAIIIDGjaoQAggQEiRraAQQQONGVQgBBAgJkjU0AgigcaMqhAAChATJGhoBBNC4URVCAAFCgmQNjcD28/vxLN22TetCFQQKEdgd+T+8AhQKjlH9BBDAz5SOhQggQKGwGNVPAAH8TOlYiMB/3gQXmptRIWAhwCuABSNNqhJAgKrJMbeFAAJYMNKkKgEEqJocc1sI/AttM9RW4CyLLgAAAABJRU5ErkJggg=='
  4. });

getStatus

获取打印机连接状态

getStatus(callback)

callback

ret:

  • 类型:JSON
  • 描述:返回打印机状态

示例代码

  1. var gprinter = api.require('xGprinter');
  2. gprinter.getStatus(function(ret) {
  3. alert(JSON.stringify(ret));
  4. });

补充说明

如果使用蓝牙连接方式,需手机打开蓝牙。目前只支持android系统。

可用性

Android系统

可提供的1.0.0及更高版本