Node.js : How to add print job to printer

前端 未结 2 919
北恋
北恋 2021-01-03 10:02

I am developing a web application using node.js where i have a scenario to print some pdf files located in my local.

Ex:

var ipp = require(\'ipp\');
         


        
2条回答
  •  -上瘾入骨i
    2021-01-03 10:23

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

提交回复
热议问题