NW.js安装原生node模块node-printer控制打印机

1.安装原生node模块
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#全局安装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
<br>安装编译不成功,就多试几次,删除package-lock.json
1
 

 

2.查看python目录:
打开我们的cmd命令
输入 Python
输入 import sys
输入 print(sys.path)

 

 

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

  为打印机安装WinUSB驱动,否则报错:LIBUSB_ERROR_NOT_SUPPORTED

 

 

 

 

 

   4.NW app项目的index.js 里 引入下面代码:

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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,打印成功。

 

posted @   盼少  阅读(7642)  评论(2编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
点击右上角即可分享
微信分享提示