3

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

I have referred the above example, but in that PDF is created but in my case i want to print the existing PDF files.

Any suggestions ???

robertklep
  • 198,204
  • 35
  • 394
  • 381
R J.
  • 1,522
  • 10
  • 25
  • 40

2 Answers2

4
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);
  });
});
robertklep
  • 198,204
  • 35
  • 394
  • 381
  • And what does `err` say? BTW, just cutting and pasting the example code obviously isn't going to work, unless your printer is located on a server called `NPI977E4E.local` as well. – robertklep Apr 24 '13 at 10:52
  • { [Error: getaddrinfo ENOENT] code: 'ENOTFOUND', errno: 'ENOTFOUND', syscall: 'getaddrinfo' } – R J. Apr 24 '13 at 10:57
  • 2
    So replace `NPI977E4E.local` with the address or hostname of your IPP server. – robertklep Apr 24 '13 at 10:57
  • i changed host name of printer and checked then its showing 'null'. – R J. Apr 24 '13 at 11:08
  • When `err` is null, that means no error occurred. Which should be a good thing. – robertklep Apr 24 '13 at 11:09
  • when i print res it shows. { version: '1.1', statusCode: 'server-error-version-not-supported', id: 36143315, 'operation-attributes-tag': { 'attributes-charset': 'utf-8', 'attributes-natural-language': 'en-us' } } – R J. Apr 24 '13 at 11:47
  • Well, I guess your problem is a bit more elaborate that just wanting to print local files instead of generated ones. It might even warrant a new (or reformulated) question to attract people with more knowledge. – robertklep Apr 24 '13 at 14:41
  • This is late, but chances are that all you needed to do was specify the version that is provided in the request. – Jim Pedid Apr 21 '15 at 13:06
0

If I understand you correctly, you want to print local PDF files, and printing works already?

Node.js has the fs api you can use to retrieve a PDF file. http://nodejs.org/api/fs.html

https://npmjs.org/package/ipp To me it doesn't seem you have to use a PDFkit object as data -property in your operation. You can just use data you can read with fs.

Eric Smekens
  • 1,602
  • 20
  • 32
  • 1
    Try to get your address and network configuration working first, and try to just print that in-line created PDF in your example. Make small steps. – Eric Smekens Apr 24 '13 at 10:59