Internet Printing Protocol (IPP) for nodejs

4.8k Views Asked by At

I am trying print the pdf file in my local using printer. This is a code, tried to print.

fs.readFile('documents/AccountStatement.pdf', function(err, data) { 
    if (err)
        throw err;
    var printer = ipp.Printer("http://hostname:631/ipp/printer");
    var msg = {
    "operation-attributes-tag": {
      "requesting-user-name": "KUMA1936",
      "job-name": "My Test Job",
      "document-format": "application/pdf"
    },
    data: data
    };
    printer.execute("Print-Job", msg, function(err, res){
        console.log(res);
        console.log(err);
    });
});

In the above code what does printer.execute() method and "Print-Job" parameter. And what does 631 here.When i print the res,its shows

{ version: '1.1', statusCode: 'server-error-operation-not-supported', id: 442076, 'operation-attributes-tag': { 'attributes-charset': 'utf-8', 'attributes-natural-language': 'en-us' } } err is null.

3

There are 3 best solutions below

0
On

You can check the API docs. The first parameter (string) is an operation defined by IPP. Description about Print-Job operation is given here

3.2.1 Print-Job Operation

   This REQUIRED operation allows a client to submit a print job with
   only one document and supply the document data (rather than just a
   reference to the data).  See Section 15 for the suggested steps for
   processing create operations and their Operation and Job Template
   attributes.

You can see other IPP supported operations here. 631 is the accepted port used for IPP, which uses TCP.

You can check more about the error here, which shows :

13.1.5.2 server-error-operation-not-supported (0x0501)

   The IPP object does not support the functionality required to fulfill
   the request. This is the appropriate response when the IPP object
   does not recognize an operation or is not capable of supporting it.
   See sections 3.1.6.1 and 3.1.7.

This means that there is no error in your code. Most likely your printer is not configured or does not support IPP. Last but not the least, the IPP.Printer has to be given the printer IP. So check the IP you are giving is valid (your code shows you gave hostname). From the project page it is given :

To find out if your printer supports IPP:

 - Google your printer's specs
 - Try: telnet YOUR_PRINTER 631. If it connects, that's a good sign.
 - Use the '/examples/findPrinters.js' script.
0
On

In my case i just share the printer : (like share with another)

So URL gonna be (you will be found by findPrinters.js)

http://My-Computer-Name.local.:631/printers/my_printer_name

This should be help if your printer donesnt connect (like USB) with your computer. But connect via lan.

0
On
  • Look's like you get an IPP-Version-1.1-Response while sending IPP-2.0.
  • Try downgrading to 1.1 by using the version-option