Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the list of all the printers installed/connected printers in Node.Js

I am creating a desktop application in Node.Js using Electron framework and want to get the list of all the printers installed/connected in Node.Js. I had already tried node-printer but it is not installing properly.

like image 920
Nirzar Avatar asked Dec 13 '25 05:12

Nirzar


1 Answers

 const { exec } = require('child_process');
  exec('wmic printer list brief', (err, stdout, stderr) => {
  if (err) {
    // node couldn't execute the command
    return;
  }
  // list of printers with brief details
  console.log(stdout);
  // the *entire* stdout and stderr (buffered)
  stdout=stdout.split("  ");
  var printers=[];
  j=0;
  stdout = stdout.filter(item => item);
  for (i = 0; i < stdout.length; i++)
  {
    if(stdout[i]==" \r\r\n" ||stdout[i]=="\r\r\n")
    {
       printers[j]=stdout[i+1];
       j++; 
    }
  }
  // list of only printers name
  console.log(printers);
  console.log(stderr);
});
like image 70
Prajakta Kate Avatar answered Dec 15 '25 05:12

Prajakta Kate