Getting list of printers attached to system using Electron.JS

Today I am to share code snippet that I used to get the list of the printers attached to my system using Electron JS. Recently I was working on a project where I have to store the default selection for printer. If I do show then during printing anything it will ask me again and again to select printer So main motive was to make the process easy.

In Electron.JS to get the printer list looks tough but it is very easy when go for implementation. Checkout the code snippet here.

handlePrint() {
        const { remote } = require('electron');
        const { BrowserWindow, dialog, shell } = remote;
        let printWindow = new BrowserWindow({ 'auto-hide-menu-bar': true,show:false });
        let list = printWindow.webContents.getPrinters();
        console.log("All printer available are ",list);

this method can be used anywhere you want whether you are using vanilla Javascript or React.Js. You can use var instead of let if you are not using ECMAScript.

I was using it with React.js.

So whole code snippet looked like this.I used Json Storage npm module to store my select choice for printer.

I am using React.js here with Electron but concept will remain same with all frameworks.

I hope this will help you to get more out of Electron.js Framework.Thanks for being here.

Tagged with:
Written by Sanjeev Kumar

Get notifications about new posts on Twitter, RSS or Email.