Electron print without dialog (silent print)

zippax picture zippax · Oct 30, 2017 · Viewed 11.3k times · Source

I just need to use electron js to build my desktop app, I use simple BrowserWindow to load my website in the application.

I added some functionality to reload the window when the connection issues so when the internet turn-on again the app will reload the page so it will not show "Page not found".

In my web page it received an orders and print it to receipt printer, I don't want the print dialog show out, is there any solution to print the receipt silently?

I know the way how to print it silent with the firefox but I need to use it now in my electron app.

my code:

Answer

ghybs picture ghybs · Oct 30, 2017

There is the silent option of BrowserWindow.webContents.print:

Prints window’s web page. When silent is set to true, Electron will pick the system’s default printer if deviceName is empty and the default settings for printing.

Calling window.print() in web page is equivalent to calling webContents.print({silent: false, printBackground: false, deviceName: ''}).

let win = new BrowserWindow(params);

win.webContents.print({silent: true});