printOnSpecifiedPrinters

2022-06-21 16:24 更新

將打印內(nèi)容發(fā)送到指定地址的打印機(jī)(藍(lán)牙打印機(jī)為MAC地址,網(wǎng)口打印機(jī)為IP地址),支持多機(jī)打印

printOnSpecifiedPrinters({params})

params

taskList:

  • 類型:JSON數(shù)組
  • 描述:(必填項)打印機(jī)、打印內(nèi)容、重復(fù)打印次數(shù)組成的JSON對象數(shù)組
  • 內(nèi)部字段:

  1. [
  2. {
  3. printerAddr: '98:D3:31:20:23:4A', //字符串;打印機(jī)地址
  4. tscSetting:{ //如果是TSC標(biāo)簽打印機(jī),這個屬性必須設(shè)置,如果忽略此屬性,則此打印機(jī)為小票打印機(jī)
  5. width:40, //標(biāo)簽的寬度,單位mm
  6. height:30, //標(biāo)簽的高度,單位mm
  7. gap:2 //每個標(biāo)簽之間的間隔,單位mm
  8. },
  9. tagContent:'<text>我的測試1</text>', //設(shè)置標(biāo)簽打印的內(nèi)容,TSC標(biāo)簽打印機(jī)專用屬性,設(shè)置此屬性,content屬性可以忽略
  10. content: orderInfo, //字符串;打印內(nèi)容
  11. keepAlive:true, //打印完畢后不斷開連接,下次打印將使用同樣的連接進(jìn)行打?。ㄋ{(lán)牙打印機(jī)建議設(shè)置為true)
  12. cmd:[25,23,0] //打印內(nèi)容的同時,一并發(fā)送指定的ESC/POS命令
  13. copyNum: 2 //數(shù)值類型;重復(fù)打印次數(shù),默認(rèn)值為1
  14. }
  15. ]

callback(ret, err)

ret:

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

  1. {
  2. result: 'ok' //字符串;ok表示調(diào)用成功
  3. }

err:

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

  1. {
  2. msg:'', //錯誤信息的匯總描述
  3. errors:[ //用一個數(shù)組,描述打印發(fā)生的錯誤
  4. {
  5. taskIndex:0, //描述哪個打印任務(wù)發(fā)生錯誤
  6. printerAddr:'', //發(fā)生錯誤的打印機(jī)地址
  7. msg:'' //錯誤信息
  8. }
  9. ],
  10. }

打印小票示例代碼(小票打印機(jī)專用)

  1. var orderInfo;
  2. orderInfo = "<CA>測試打印</CA><BR>";
  3. orderInfo += "名稱      單價 數(shù)量 金額<BR>";
  4. orderInfo += "--------------------------------<BR>";
  5. orderInfo += "番       1.0 1 1.0<BR>";
  6. orderInfo += "番茄      10.0 10 10.0<BR>";
  7. orderInfo += "番茄炒     10.0 100 100.0<BR>";
  8. orderInfo += "番茄炒粉    100.0 100 100.0<BR>";
  9. orderInfo += "番茄炒粉粉   1000.0 1 100.0<BR>";
  10. orderInfo += "番茄炒粉粉粉粉 100.0 100 100.0<BR>";
  11. orderInfo += "番茄炒粉粉粉粉 15.0 1 15.0<BR>";
  12. orderInfo += "備注:快點送到<BR>";
  13. orderInfo += "--------------------------------<BR>";
  14. orderInfo += "合計:xx.0元<BR>";
  15. orderInfo += "送貨地點:xxxxxxxxxxxxxxxxx<BR>";
  16. orderInfo += "聯(lián)系電話:138000000000<BR>";
  17. orderInfo += "訂餐時間:2011-01-06 19:30:10<BR>";
  18. orderInfo += "<QR>(300)http://www.baidu.com</QR><BR>";
  19. orderInfo += " <CUT>";
  20. var printModule = api.require('posPrinter');
  21. var param =
  22. {
  23. taskList:
  24. [
  25. {
  26. printerAddr: '98:D3:31:20:23:4A',
  27. content: orderInfo,
  28. keepAlive:true, //藍(lán)牙打印機(jī),建議把keepAlive設(shè)為true
  29. copyNum: 2
  30. },
  31. {
  32. printerAddr: '192.168.1.10',
  33. content: orderInfo,
  34. copyNum: 2
  35. }
  36. ]
  37. };
  38. printModule.printOnSpecifiedPrinters(param);

打印標(biāo)簽示例代碼(標(biāo)簽打印機(jī)專用)

  1. var printModule = api.require('posPrinter');
  2. var param =
  3. {
  4. taskList:
  5. [
  6. {
  7. printerAddr: 'u:85:Printer',
  8. tscSetting:{
  9. width:40,
  10. height:30,
  11. gap:2
  12. },
  13. tagContent:'<text size="30" bold="true" left="10" top="10">我的測試1</text><qr left="10" top="85" width="150">http://www.cailutong168.com</qr><img left="10" top="70">base64內(nèi)容</img>',
  14. //<qr>標(biāo)簽表示打印二維碼
  15. //tagContent里面所有標(biāo)簽都支持旋轉(zhuǎn)屬性,如rotate="45"表示旋轉(zhuǎn)45度
  16. //text標(biāo)簽可以使用center="1"表示居中,如果居中時,設(shè)置left="-10",表示居中后,再往左偏移10
  17. keepAlive:true, //usb打印機(jī),建議把keepAlive設(shè)為true
  18. copyNum: 1
  19. }
  20. ]
  21. };
  22. printModule.printOnSpecifiedPrinters(param);

可用性

iOS系統(tǒng)

可提供的1.0.0及更高版本

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

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號