Node.js:如何向打印机添加打印作业 [英] Node.js : How to add print job to printer
本文介绍了Node.js:如何向打印机添加打印作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用node.js开发一个Web应用程序,其中有一个方案可以打印一些位于本地的pdf文件.
I am developing a web application using node.js where i have a scenario to print some pdf files located in my local.
例如:
var ipp = require('ipp');
var PDFDocument = require('pdfkit');
//make a PDF document
var doc = new PDFDocument({margin:0});
doc.text(".", 0, 780);
doc.output(function(pdf){
var printer = ipp.Printer("http://NPI977E4E.local.:631/ipp/printer");
var msg = {
"operation-attributes-tag": {
"requesting-user-name": "William",
"job-name": "My Test Job",
"document-format": "application/pdf"
},
data: pdf
};
printer.execute("Print-Job", msg, function(err, res){
console.log(res);
});
});
我已经提到了上面的示例,但是在创建PDF的同时,我想打印现有的PDF文件.
I have referred the above example, but in that PDF is created but in my case i want to print the existing PDF files.
任何建议???
推荐答案
var fs = require('fs');
fs.readFile('filename.pdf', function(err, data) {
if (err)
throw err;
var printer = ipp.Printer("http://YOUR.PRINTER.SERVER.HOSTNAME:631/ipp/printer");
var msg = {
"operation-attributes-tag": {
"requesting-user-name": "William",
"job-name": "My Test Job",
"document-format": "application/pdf"
},
data: data
};
printer.execute("Print-Job", msg, function(err, res){
console.log(res);
});
});
这篇关于Node.js:如何向打印机添加打印作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文