Skip to content

Instantly share code, notes, and snippets.

@Samuell1
Last active April 24, 2018 06:47
Show Gist options
  • Save Samuell1/b0d8d9a8701b2ff0dbb84531d86667b9 to your computer and use it in GitHub Desktop.
Save Samuell1/b0d8d9a8701b2ff0dbb84531d86667b9 to your computer and use it in GitHub Desktop.
ElectronJs
ipcMain.on('printPdf', (event, pdf) => {
printWindow = new BrowserWindow({width: 800, height: 600})
printWindow.loadURL("data:text/html," + pdf)
printWindow.webContents.on("did-finish-load", function() {
// Use default printing options
printWindow.webContents.printToPDF({}, function(error, data) {
if (error) throw error
fs.writeFile(app.getPath('desktop') + '/test.pdf', data, function(err) {
if (err)
alert('write pdf file error', error)
})
event.sender.send('printPdf-reply', true)
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment