NW.js安裝原生node模塊node-printer控制打印機


1.安裝原生node模塊
 
         
#全局安裝nw-gyp
npm install -g nw-gyp
#設置目標NW.js版本
set npm_config_target=0.31.4
#設置構建架構,ia32或x64,win10, osx為x64操作系統
set npm_config_arch=x64
set npm_config_runtime=node-webkit
set npm_config_build_from_source=true
set npm_config_node_gyp=C:\Users\NALA\AppData\Roaming\npm\node_modules\nw-gyp\bin\nw-gyp.js

#win10下還要設置python路徑:
set PYTHON=C:\Users\NALA\.windows-build-tools\python27\python.exe

最后 npm install —msvs_version=2015

安裝編譯不成功,就多試幾次,刪除package-lock.json
 
         
        

 

2.查看python目錄:
打開我們的cmd命令
輸入 Python
輸入 import sys
輸入 print(sys.path)

 

 

3.下載Zadighttp://zadig.akeo.ie/  

  為打印機安裝WinUSB驅動,否則報錯:LIBUSB_ERROR_NOT_SUPPORTED

 

 

 

 

 

   4.NW app項目的index.js 里 引入下面代碼:

 

const escpos = nw.require('escpos');
const device  = new escpos.USB();
const options = { encoding: 'GB18030'};
let printerList = escpos.USB.findPrinter();

const printer = new escpos.Printer(device, options);

console.log(printerList);
device.open(function(){
  printer
  .font('a')
  .align('ct')
  .style('bu')
  .size(1, 1)
  .text('The quick brown fox jumps over the lazy dog')
  .text('敏捷的棕色狐狸跳過懶狗')
  .barcode('1234567', 'EAN8')
  .qrimage('https://github.com/song940/node-escpos', function(err){
    this.cut();
    this.close();
  });
});

  

5. CMD終端cd到nw sdk目錄,輸入 nw myapp 啟動客戶端

OK,打印成功。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM