W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
設(shè)置打印數(shù)據(jù)并打印
printData({params}, callback(ret, err))
data:
[{
rowtype: 'printText',//打印文字,文字寬度滿一行自動(dòng)換行排版,不滿一整行不打印除非強(qiáng)制換行
text : '要打印的文字字符串' //要打印的文字字符串
},{
rowtype: 'printOriginalText', //文字按矢量文字寬度原樣輸出,即每個(gè)字符不等寬
text : '要打印的文字字符串' //要打印的文字字符串
},{
rowtype: 'printTextWithFont', //打印指定字體的文本,字體設(shè)置只對(duì)本次有效
text : '要打印的文字字符串', //要打印的文字字符串
typeface:'', //字體名稱(chēng)(目前只支持"gh"字體)
fontsize:12 //字體大小
},{
rowtype: 'printColumnsText', //打印表格的一行,可以指定列寬、對(duì)齊方式
colsTextArr : ['商品名稱(chēng)','數(shù)量','單位','金額'], //各列文本字符串?dāng)?shù)組
colsWidthArr : [10, 6, 6, 8], //各列寬度數(shù)組(以英文字符計(jì)算, 每個(gè)中文字符占兩個(gè)英文字符, 每個(gè)寬度大于0)
colsAlign : [0, 2, 2, 2] //各列對(duì)齊方式(0居左, 1居中, 2居右)
//備注: 三個(gè)參數(shù)的數(shù)組長(zhǎng)度應(yīng)該一致, 如果colsText[i]的寬度大于colsWidth[i], 則文本換行
},{
rowtype: 'setFontSize', //設(shè)置字體大小, 對(duì)之后打印有影響,除非初始化
fontsize:12 //字體大小
},{
rowtype: 'lineWrap', //打印機(jī)走紙(強(qiáng)制換行,結(jié)束之前的打印內(nèi)容后走紙n行)
n:3 //走紙行數(shù)
},{
rowtype: 'setAlignment', //設(shè)置對(duì)齊模式,對(duì)之后打印有影響,除非初始化
alignment:0 //對(duì)齊方式 0--居左 , 1--居中, 2--居右
},{
rowtype: 'printBarCode', //打印一維條碼
data:'123456', //條碼數(shù)據(jù)
symbology:8,//0-8
width:160, //條碼寬度: 取值2至6, 默認(rèn)2
height:160, //條碼高度:取值1到255, 默認(rèn)162
textposition : 2 //文字位置 0--不打印文字, 1--文字在條碼上方, 2--文字在條碼下方, 3--條碼上下方均打印
},{
rowtype: 'printQRCode', //打印二維條碼
data:'www.hanchao9999.com', //二維碼數(shù)據(jù)
size:240 //二維碼塊大小(單位:點(diǎn))
},{
rowtype: 'printBitmap', //打印圖片
image:'widget://res/Images/1.jpg' //圖片bitmap對(duì)象(最大寬度384像素,超過(guò)無(wú)法打印并且回調(diào)callback異常函數(shù)) 支持widget:// fs://
},{
rowtype: 'printTypeHorizontalLine', //畫(huà)特殊水平線
type:0, //水平線類(lèi)型(0至11)
}]
條碼說(shuō)明(不同機(jī)型略有不同)
編碼 | 說(shuō)明 |
---|---|
code39 | 最長(zhǎng)打印 13 個(gè)數(shù)字 |
code93 | 最長(zhǎng)打印 17 個(gè)數(shù)字 |
code128 | 最長(zhǎng)打印 15 個(gè)數(shù)字 |
ean8 | 要求 8 位數(shù)字(最后一位校驗(yàn)位) ,有效長(zhǎng)度 8 個(gè)數(shù)字 |
ean13 | 有效長(zhǎng)度 13 個(gè)數(shù)字,其中最后一位為校驗(yàn)位 |
ITF | 要求輸入數(shù)字,且有效小于 14 位,必須是偶數(shù)位 |
Codebar | 要求 0-9 及 6 個(gè)特殊字符,最長(zhǎng)打印 18 個(gè)數(shù)字 |
UPC-E | 要求 8 位數(shù)字(最后一位校驗(yàn)位) |
UPC-A | 要求 12 位數(shù)字(最后一位校驗(yàn)位) |
ret:
{
status: true, //false
print:"打印完畢"
}
var obj = api.require('sunmiT1Printer');
obj.printData({
data : [{
rowtype : 'printColumnsText',
colsTextArr : ['名稱(chēng)','數(shù)量','單價(jià)','金額'],
colsWidthArr : [10, 6, 6, 8],
colsAlign : [1, 2, 2, 2]
},{
rowtype : 'printColumnsText',
colsTextArr : ['大白兔奶糖','4','12.00','48.00'],
colsWidthArr : [10, 6, 6, 8],
colsAlign : [0, 2, 2, 2]
},{
rowtype : 'printText',
text : '支付寶\n'
}, {
rowtype : 'printText',
text : 'Alipay\n'
}, {
rowtype : 'printText',
text : '===============================\n'
}, {
rowtype : 'printText',
text : '訂單金額 0.01元\n'
}, {
rowtype : 'printText',
text : ' 參與優(yōu)惠金額 0.01元\n'
}, {
rowtype : 'printText',
text : '商家實(shí)收\(chéng)n'
}, {
rowtype : 'printText',
text : '-------------------------------\n'
}, {
rowtype : 'printText',
text : '開(kāi)票金額(用戶實(shí)付) 0.01元\n'
}, {
rowtype : 'printText',
text : '--------------------------------\n'
}, {
rowtype : 'printText',
text : '交易號(hào):\n'
}, {
rowtype : 'printText',
text : '201805291136661631631\n'
}, {
rowtype : 'printText',
text : '門(mén)店名稱(chēng) 北國(guó)超市(新石店)\n'
}, {
rowtype : 'printText',
text : '買(mǎi)家?guī)ぬ?hào) service@hanchao9999.com\n'
}, {
rowtype : 'printText',
text : '--------------------------------\n'
}, {
rowtype : 'printText',
text : '日期 2018-05-26 11:36\n'
}, {
rowtype : 'printText',
text : '--------------------------------\n'
}, {
rowtype : 'printText',
text : '此小票不需要用戶簽字\n'
}, {
rowtype : 'setFontSize',
fontsize : 32
}, {
rowtype : 'printText',
text : 'http://www.hanchao9999.com\n'
}, {
rowtype : 'printOriginalText',
text : 'http://www.hanchao9999.com\n'
}, {
rowtype : 'setFontSize',
fontsize : 24
}, {
rowtype : 'printText',
text : 'http://www.hanchao9999.com\n'
}, {
rowtype : 'printOriginalText',
text : 'http://www.hanchao9999.com\n'
}, {
rowtype : 'lineWrap',
n : 2
}, {
rowtype : 'setAlignment',
alignment : 1
}, {
rowtype : 'printBarCode',
data : '123456',
width : 160,
height : 160
}, {
rowtype : 'setAlignment',
alignment : 1
}, {
rowtype : 'printQRCode',
data : 'http://www.hanchao9999.com',
size : 240
}, {
rowtype : 'printTypeHorizontalLine',
type : 0
}, {
rowtype : 'printTypeHorizontalLine',
type : 1
}, {
rowtype : 'printTypeHorizontalLine',
type : 2
}, {
rowtype : 'printTypeHorizontalLine',
type : 3
}, {
rowtype : 'printBitmap',
image : 'widget://res/Images/1.jpg'
}, {
rowtype : 'lineWrap',
n : 3
}]
}, function(ret, err) {
alert(JSON.stringify(ret));
});
Android系統(tǒng)
可提供的1.0.0及更高版本
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: