2

The print dialog doesn't seem to appear when I have no printers attached with electron's built in printing. Right now I wait for the webpage to load then I print the page but no print message is displayed and no print error is displayed. I print dialog does appear I have a printer attached but doesn't appear and gives no error message when I don't.

win.webContents.on('did-finish-load', function() {
    try {
        console.log('Print Message: ', win.webContents.print({silent: false}));         
    }
    catch(e) {
        console.log('Print Error: ', e);
    }
}); 

Is there a way to check if the print dialog opened or the user has no printer available? Or even catch errors in electron printing?

Mike Cluck
  • 31,869
  • 13
  • 80
  • 91
  • I don't think so. – SaidbakR Sep 08 '16 at 21:11
  • Is there any way to then just check if there is a printer attached in javascript then? – Kobe Bryant Sep 08 '16 at 21:14
  • You could [check if the user has any printers](https://github.com/tojocky/node-printer) using a separate module. – Mike Cluck Sep 08 '16 at 21:14
  • @MikeC node-printer doesn't seem to be package-able with electron since I got it to work on my local machine but wasn't able to build it and put it in an exe since the Visual Studio and Python dependencies – Kobe Bryant Sep 08 '16 at 21:17
  • @KobeBryant Check out [this issue](https://github.com/tojocky/node-printer/issues/113) which may address that problem for you. – Mike Cluck Sep 08 '16 at 21:19

1 Answers1

0

You can pass a function as callback and get the response that includes error if execution is not successful.

win.webContents.print(options, (success, errorType) => {
  // if error, log error reason
  if (!success) console.log(errorType)
})

You can also use win.webContents.getPrinters to get system printer list.

webContents Print

Get Printers

Bilal Akbar
  • 4,659
  • 1
  • 18
  • 29