printingdefaultnode-webkitprintersnwjs

NWJS(Node-Webkit): How to get the default printer?


I'm using NWJS (node-webkit) for an app where I need to print. From the docs I see we can get a list of available printers with win.getPrinters(callback) however there is no way to know which one has been set as the default printer (by the OS?). I feel its possible because other softwares are able to detect and automatically select the default printer which is exactly what i'm trying to do. I didn't see any other function that could help in this. So how do we do that ?


Solution

  • Use a node module. Example:

    npm install --save systeminformation

    const si = require('systeminformation');
    
    si.printer()
      .then((printers) => {
        if (printers.length) {
          const defaultPrinter = printers.find((printer) => {
            return printer.default;
          });
          console.log({ printers, defaultPrinter });
        } else {
          console.log('No printers on this machine.');
        }
      });
      .catch((error) => {
        console.log('Error checking printers', error);
      });