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.
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);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With