从 Electron 应用程序打印 [英] Print from an Electron application

查看:41
本文介绍了从 Electron 应用程序打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 Electron 应用程序中使用 节点打印机,但我很快添加使用打印机的行,应用程序崩溃.

I'm trying to use node printer from an Electron application, but as soon I add the lines to use the printer, the app crashes.

控制台输出:

[1]    9860 segmentation fault (core dumped)  node_modules/electron-prebuilt/dist/electron.

这是我正在运行的应用程序:

This is the app I'm running:

var app = require('app');
var BrowserWindow = require('browser-window');
var printer = require('printer');

require('crash-reporter').start();

app.on('ready', function() {
  var mainWindow = new BrowserWindow({width: 800, height: 600});
  mainWindow.loadUrl('file://' + __dirname + '/app/index.html');

  mainWindow.openDevTools();

  printer.printDirect({data:"print from Node.JS buffer" // or simple String: "some text"
      , printer:'HP-Deskjet-F4400-series' // printer name, if missing then will print to default printer
      , type: 'TEXT' // type: RAW, TEXT, PDF, JPEG, .. depends on platform
      , success:function(jobID){
          console.log("sent to printer with ID: "+jobID);
      }
      , error:function(err){console.log(err);}
  });      
});

我错过了什么吗?

我自己尝试了节点打印机,我成功打印了一些乱码.

I tried the node printer on its own, and I successfully printed some gibberish text.

推荐答案

node-printer 使用本机绑定并根据 文档:

node-printer uses native bindings and according to the docs:

Electron 支持原生 Node 模块,但由于 Electron使用与官方 Node 不同的 V8 版本,你必须在构建时手动指定 Electron 头文件的位置原生模块.

The native Node modules are supported by Electron, but since Electron is using a different V8 version from official Node, you have to manually specify the location of Electron's headers when building native modules.

我想这就是您收到 seg fault 的原因.尝试针对文档中提到的电子标题构建模块:

I suppose that is why you are getting the seg fault. Try to build the module against the electron headers as mentioned in the docs:

npm install --save-dev electron-rebuild

# Every time you run npm install, run this too
./node_modules/.bin/electron-rebuild

这篇关于从 Electron 应用程序打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆