Printing a PDF file with Electron JS

Printing a PDF file with Electron JS



 To print a PDF file using Electron JS, you can use the webContents module to load the PDF file and then use the print method to initiate the print dialog. Here is an example code snippet:

const { BrowserWindow } = require('electron'
let win = new BrowserWindow({width: 800, height: 600})
win.loadURL('path/to/pdf/file.pdf') win.webContents.on('did-finish-load', () =>
 win.webContents.print({printBackground: true})
})

This code creates a new BrowserWindow with a specified width and height, then loads the PDF file at the specified path. The webContents.on method is used to listen for the 'did-finish-load' event, and when the event fires, the print method is called. The printBackground option is set to true to print background colors and images.

Note: This will open print dialog box, you need to select print option from this dialog box to print the pdf.

Post a Comment

0 Comments