Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/381.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用Node.js将docx文件打印到打印机_Javascript_Node.js_Printing_Printers - Fatal编程技术网

Javascript 如何使用Node.js将docx文件打印到打印机

Javascript 如何使用Node.js将docx文件打印到打印机,javascript,node.js,printing,printers,Javascript,Node.js,Printing,Printers,我试图在node.js中编写一个程序,允许用户将docx文件打印到打印机上 任何人都可以在Node.js中演示它是如何完成的?您可以使用该模块 下面是如何使用它打印文件的示例: // use: node printFile.js [filePath printerName] var printer = require("printer"), filename = process.argv[2] || __filename; console.log('platform:', proces

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

任何人都可以在Node.js中演示它是如何完成的?

您可以使用该模块

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

// 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);
    }
  });
}

打印机不是一个模块,当我将其更改为
require('node-printer')
printDirect不是一个函数。。。。。。。。。