printData

2022-06-21 16:08 更新

設(shè)置打印數(shù)據(jù)

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

params

data:

  • 類型:數(shù)組
  • 描述:(必輸項)打印數(shù)據(jù)。

  1. [{
  2. rowtype: 'printText',//打印文字,文字寬度滿一行自動換行排版,不滿一整行不打印除非強制換行
  3. text : '' //要打印的文字字符串
  4. },{
  5. rowtype: 'printOriginalText', //文字按矢量文字寬度原樣輸出,即每個字符不等寬
  6. text : '' //要打印的文字字符串
  7. },{
  8. rowtype: 'printTextWithFont', //打印指定字體的文本,字體設(shè)置只對本次有效
  9. text : '', //要打印的文字字符串
  10. typeface:'', //字體名稱(目前只支持"gh"字體)
  11. fontsize:12 //字體大小
  12. },{
  13. rowtype: 'printColumnsText', //打印表格的一行,可以指定列寬、對齊方式
  14. colsTextArr : ['名稱','數(shù)量','單價','金額'], //各列文本字符串數(shù)組
  15. colsWidthArr : [10, 6, 6, 8], //各列寬度數(shù)組(以英文字符計算, 每個中文字符占兩個英文字符, 每個寬度大于0)
  16. colsAlign : [0, 2, 2, 2] //各列對齊方式(0居左, 1居中, 2居右)
  17. //備注: 三個參數(shù)的數(shù)組長度應(yīng)該一致, 如果colsText[i]的寬度大于colsWidth[i], 則文本換行
  18. },{
  19. rowtype: 'setFontSize', //設(shè)置字體大小, 對之后打印有影響,除非初始化
  20. fontsize:12 //字體大小
  21. },{
  22. rowtype: 'lineWrap', //打印機走紙(強制換行,結(jié)束之前的打印內(nèi)容后走紙n行)
  23. n:3 //走紙行數(shù)
  24. },{
  25. rowtype: 'setAlignment', //設(shè)置對齊模式,對之后打印有影響,除非初始化
  26. alignment:0 //對齊方式 0--居左 , 1--居中, 2--居右
  27. },{
  28. rowtype: 'printBarCode', //打印一維條碼
  29. data:'', //條碼數(shù)據(jù)
  30. symbology:8,//0-8
  31. width:160, //條碼寬度: 取值2至6, 默認2
  32. height:160, //條碼高度:取值1到255, 默認162
  33. textposition : 2 //文字位置 0--不打印文字, 1--文字在條碼上方, 2--文字在條碼下方, 3--條碼上下方均打印
  34. },{
  35. rowtype: 'printQRCode', //打印二維條碼
  36. data:'', //二維碼數(shù)據(jù)
  37. size:240 //二維碼塊大小(單位:點)
  38. },{
  39. rowtype: 'printBitmap', //打印圖片
  40. image:'widget://res/Images/1.jpg' //圖片bitmap對象(最大寬度384像素,超過無法打印并且回調(diào)callback異常函數(shù)) 支持widget:// fs://
  41. },{
  42. rowtype: 'printTypeHorizontalLine', //畫特殊水平線
  43. type:0, //水平線類型(0至11)
  44. },{
  45. rowtype: 'cutPaper'//切紙
  46. }]

callback(ret, err)

ret:

  • 類型:JSON對象
  • 內(nèi)部字段:

  1. {
  2. status: true, //布爾型;true||false
  3. result : //
  4. }

err:

  • 類型:JSON對象
  • 內(nèi)部字段:

  1. {
  2. code: "",
  3. msg:""
  4. }

示例代碼

  1. var obj = api.require('sunmiPrinter');
  2. obj.printData({
  3. data : [{
  4. rowtype : 'printColumnsText',
  5. colsTextArr : ['名稱','數(shù)量','單價','金額'],
  6. colsWidthArr : [10, 6, 6, 8],
  7. colsAlign : [1, 2, 2, 2]
  8. },{
  9. rowtype : 'printColumnsText',
  10. colsTextArr : ['草莓酸奶A布甸','4','12.00','48.00'],
  11. colsWidthArr : [10, 6, 6, 8],
  12. colsAlign : [0, 2, 2, 2]
  13. },{
  14. rowtype : 'printText',
  15. text : '支付寶\n'
  16. }, {
  17. rowtype : 'printText',
  18. text : 'Alipay\n'
  19. }, {
  20. rowtype : 'printText',
  21. text : '===============================\n'
  22. }, {
  23. rowtype : 'printText',
  24. text : '訂單金額 0.01元\n'
  25. }, {
  26. rowtype : 'printText',
  27. text : ' 參與優(yōu)惠金額 0.01元\n'
  28. }, {
  29. rowtype : 'printText',
  30. text : '商家實收\n'
  31. }, {
  32. rowtype : 'printText',
  33. text : '-------------------------------\n'
  34. }, {
  35. rowtype : 'printText',
  36. text : '開票金額(用戶實付) 0.01元\n'
  37. }, {
  38. rowtype : 'printText',
  39. text : '--------------------------------\n'
  40. }, {
  41. rowtype : 'printText',
  42. text : '交易號:\n'
  43. }, {
  44. rowtype : 'printText',
  45. text : '2016040621001004150224503623\n'
  46. }, {
  47. rowtype : 'printText',
  48. text : '門店名稱 正新雞排(歡樂谷二店)\n'
  49. }, {
  50. rowtype : 'printText',
  51. text : '買家?guī)ぬ? 1id***@21cn.com\n'
  52. }, {
  53. rowtype : 'printText',
  54. text : '--------------------------------\n'
  55. }, {
  56. rowtype : 'printText',
  57. text : '日期 2016-04-06 11:29\n'
  58. }, {
  59. rowtype : 'printText',
  60. text : '--------------------------------\n'
  61. }, {
  62. rowtype : 'printText',
  63. text : '此小票不需要用戶簽字\n'
  64. }, {
  65. rowtype : 'setFontSize',
  66. fontsize : 32
  67. }, {
  68. rowtype : 'printText',
  69. text : 'http://www.sunmi.com\n'
  70. }, {
  71. rowtype : 'printOriginalText',
  72. text : 'http://www.sunmi.com\n'
  73. }, {
  74. rowtype : 'setFontSize',
  75. fontsize : 24
  76. }, {
  77. rowtype : 'printText',
  78. text : 'http://www.sunmi.com\n'
  79. }, {
  80. rowtype : 'printOriginalText',
  81. text : 'http://www.sunmi.com\n'
  82. }, {
  83. rowtype : 'lineWrap',
  84. n : 2
  85. }, {
  86. rowtype : 'setAlignment',
  87. alignment : 1
  88. }, {
  89. rowtype : 'printBarCode',
  90. data : '6921505036025',
  91. width : 160,
  92. height : 160
  93. }, {
  94. rowtype : 'setAlignment',
  95. alignment : 1
  96. }, {
  97. rowtype : 'printQRCode',
  98. data : 'http://www.sunmi.com',
  99. size : 240
  100. }, {
  101. rowtype : 'printTypeHorizontalLine',
  102. type : 0
  103. }, {
  104. rowtype : 'printTypeHorizontalLine',
  105. type : 1
  106. }, {
  107. rowtype : 'printTypeHorizontalLine',
  108. type : 2
  109. }, {
  110. rowtype : 'printTypeHorizontalLine',
  111. type : 3
  112. }, {
  113. rowtype : 'printTypeHorizontalLine',
  114. type : 4
  115. }, {
  116. rowtype : 'printTypeHorizontalLine',
  117. type : 5
  118. }, {
  119. rowtype : 'printTypeHorizontalLine',
  120. type : 6
  121. }, {
  122. rowtype : 'printTypeHorizontalLine',
  123. type : 7
  124. }, {
  125. rowtype : 'printTypeHorizontalLine',
  126. type : 8
  127. }, {
  128. rowtype : 'printTypeHorizontalLine',
  129. type : 9
  130. }, {
  131. rowtype : 'printTypeHorizontalLine',
  132. type : 10
  133. }, {
  134. rowtype : 'printTypeHorizontalLine',
  135. type : 11
  136. }, {
  137. rowtype : 'printBitmap',
  138. image : 'widget://res/Images/1.jpg'
  139. }, {
  140. rowtype : 'lineWrap',
  141. n : 3
  142. }]
  143. }, function(ret, err) {
  144. alert(JSON.stringify(ret));
  145. });

可用性

Android系統(tǒng)

可提供的1.0.2及更高版本

以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號