Reputation: 2029
I have a pritter connected via USB port to my PC. I run Windows 7.
Here is simple code:
var ipp=require('ipp')
var fs = require('fs');
fs.readFile('filename.pdf', function(err, data) {
if (err)
throw err;
var printer = ipp.Printer("http://localhost/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){
if(err){
console.log(err);
}
console.log(res);
});
});
How can i resolve my local priter address to write it here:
var printer = ipp.Printer("http://localhost/ipp/printer");
?
Upvotes: 4
Views: 4727
Reputation: 489
Quite an old question but I've just resolved my own issues with this module.
Working example:
var ipp = require("ipp");
var PDFDocument = require("pdfkit");
var doc = new PDFDocument;
doc.text("Hello World");
var buffers = [];
doc.on('data', buffers.push.bind(buffers));
doc.on('end', function () {
console.log(Buffer.concat(buffers));
var printer = ipp.Printer("http://192.168.1.50:631", {version:'1.0'});
var file = {
"operation-attributes-tag":{
"requesting-user-name": "User",
"job-name": "Print Job",
"document-format": "application/octet-stream"
},
data: Buffer.concat(buffers)
};
printer.execute("Print-Job", file, function (err, res) {
console.dir(res);
});
});
doc.end();
The newer version of IPP requires you to format your data into a stream, despite the current example on the IPP github page.
You'll have to play around with the settings: the printer URL, the version parameter (1.0 or 2.0 depending on your printer) and importantly the document-format.
Running the following will log out your printer's details if a connection is made which could provide further insight if you continue to have issues:
var ipp = require("ipp");
var printer = ipp.Printer('http://192.168.1.50:631', { //your printer's IP with the IPP port (631) appended
version: '1.0' //try 1.0 or 2.0
});
printer.execute('Get-Printer-Attributes', null, function (err, res) {
console.log(res);
});
Upvotes: 6