如何使用 Node.js 将 docx 文件打印到打印机 [英] How to print a docx file to a printer using Node.js

查看:230
本文介绍了如何使用 Node.js 将 docx 文件打印到打印机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 node.js 中编写一个程序,该程序将允许用户将 docx 文件打印到打印机.

I am trying to write a program in node.js that will allow the user to print a docx file to the printer.

谁能告诉我它是如何在 Node.js 中完成的?

anyone that can show me how its done in Node.js?

推荐答案

您可以使用 node-printer 模块.

以下是如何使用它打印文件的示例:

Here's example how to use it to print a file:

// use: node printFile.js [filePath printerName]
var printer = require("printer"),
    filename = process.argv[2] || __filename;

console.log('platform:', process.platform);
console.log('try to print file: ' + filename);

if( process.platform != 'win32') {
  printer.printFile({filename:filename,
    printer: process.env[3], // printer name, if missing then will print to default printer
    success:function(jobID){
      console.log("sent to printer with ID: "+jobID);
    },
    error:function(err){
      console.log(err);
    }
  });
} else {
  // not yet implemented, use printDirect and text
  var fs = require('fs');
  printer.printDirect({data:fs.readFileSync(filename),
    printer: process.env[3], // printer name, if missing then will print to default printer
    success:function(jobID){
      console.log("sent to printer with ID: "+jobID);
    },
    error:function(err){
      console.log(err);
    }
  });
}

这篇关于如何使用 Node.js 将 docx 文件打印到打印机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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