Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perform print operation on cups using Node.js

Tags:

node.js

cups

I would like to print documents through http requests on Node.js. Is there any way to send print jobs and query CUPS server using Node.js. I found this project while exploring around, is it the only/correct way to do that??

like image 342
Rahul Bhooteshwar Avatar asked Jun 23 '15 11:06

Rahul Bhooteshwar


1 Answers

You could use the shell to do so. I built a project some time ago where I needed to read certain hashtag from instagram and print the photos uploaded to IG with that hashtag using a raspberry pi and a photo printer.

var fs = require('fs'),
    exec = require('child_process').exec;

exec("lp /path/to/somepic.jpg");

// get printer jobs
exec("lpq",function (error, stdout, stderr) {
    console.log('stdout: ' + stdout);
    console.log('stderr: ' + stderr);

    if (error !== null) {
      console.log('exec error: ' + error);
    }
});

The command lp /path/to/somepic.jpg sends /path/to/somepic.jpg to the default printer. The command lpq displays the printer queue. For better use, read the CUPS documentation.

like image 178
tin Avatar answered Oct 22 '22 21:10

tin