添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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

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

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);
                printer is not a module, and when I change it to require('node-printer') printDirect is not a function.........
– garryp
                Oct 19, 2018 at 9:48
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.