

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:

const electron = require('electron')
const app = electron.app
const BrowserWindow = electron.BrowserWindow

const path = require('path')
const url = require('url')

let mainWindow

function createWindow () {
  mainWindow = new BrowserWindow({
    width: 800,
    height: 600,
    minWidth: 800,
    minHeight: 600,
    icon: __dirname + '/icon.ico'

    pathname: path.join(__dirname, 'index.html'),
    protocol: 'file:',
    slashes: true

  mainWindow.on('closed', function () {
    mainWindow = null


app.on('ready', createWindow)

  if (process.platform !== 'darwin') {

app.on('activate', function () {
  if (mainWindow === null) {

  • Hey, did you find a solution? – Kimy BF Nov 10 '17 at 19:53

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});
| improve this answer | |
  • Hello, I tried this in my code but it still show the print dialog, I use mac os. I dont know if it will work in windows or not but It should work for any OS – zippax Oct 30 '17 at 14:22
  • @ghybs Not even working in windows. It opens up print dialog box. – mayank Apr 12 '18 at 12:17
  • @mayank Feel free to open a new question with relevant details and code to reproduce your issue. – ghybs Apr 12 '18 at 12:21
  • const BrowserWindow = electron.BrowserWindow const ipc = electron.ipcMain const shell = electron.shell ipc.on('print-to-pdf', function (event) { const pdfPath = path.join(os.tmpdir(), 'print.pdf') const win = BrowserWindow.fromWebContents(event.sender) win.webContents.print({silent: true}, function (error, data) { fs.writeFile(pdfPath, data, function (error) { /*print docment*/ }) I have changed electron-api-demos\main-process\media\pdf.js file and by passing the parameter silent:true, which still prompt me with print dialogbox while printing. – mayank Apr 12 '18 at 12:45
  • @ghybs as firefox 57+ version jsprint addon not working anymore so i am not able print document silently. – mayank Apr 12 '18 at 12:59

I don't know if this helps your specific situation, but I ran into an issue where I needed to print raw text to a dot matrix printer with a couple of command codes attached (Epson ESC/P) from an Electron app running on Windows. What I ended up doing is writing the plain text along with command codes to a .txt file, and then passing the file to the Windows 'print' command. It prints silent and works great. The only issue you might have is that it feeds the rest of the page out after the job, although I do not know if a receipt printer would do the same thing. Here is the code I used:

var fs = require('fs');
var printString = "whatever text you need to print with optional ascii commands";
var printer = "lpt1";

var tmpFileName ="c:\tmp.txt";

var child = require('child_process').exec;
child('print /d:' + printer + ' "' + tmpFileName + '"');

The 'printer' variable can be either lpt1/lpt2 or a network printer share. See the reference for the print command here:


I haven't tried it, but I'm sure something similar can be hashed out for Mac/Linux using the lpr command.

Anyway, hope this helps somebody. I spent a day trying to find a native Electron way to print to our old dot matrix using the printers' built in fonts, and it turns out just issuing a simple Windows command was all I needed.

| improve this answer | |

Your Answer

