zoukankan      html  css  js  c++  java
  • 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:UsersNALAAppDataRoaming
    pm
    ode_modules
    w-gypin
    w-gyp.js
    
    #win10下还要设置python路径:
    set PYTHON=C:UsersNALA.windows-build-toolspython27python.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,打印成功。

  • 相关阅读:
    linux启动流程
    监控命令
    ansible组
    公钥和秘钥
    SSH协议介绍
    Java并发编程笔记之ThreadLocal内存泄漏探究
    【死磕 Java 集合】— ConcurrentSkipListMap源码分析
    GraphX介绍
    Storm内部的消息传递机制
    JanusGraph Server配置
  • 原文地址:https://www.cnblogs.com/pannysp/p/9687743.html
Copyright © 2011-2022 走看看