Last active
February 24, 2016 05:29
-
-
Save jlord/c883071b3123314e4487 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var printPDFBton = document.getElementById('print-pdf'); | |
var ipc = require('electron').ipcRenderer; | |
printPDFBton.addEventListener('click', function (event) { | |
ipc.send('print-to-pdf'); | |
}); | |
ipc.on('wrote-pdf', function (event, path) { | |
// TODO should we open the pdf? or put it somewhere else? | |
var message = 'Wrote PDF to: ~' + path; | |
document.getElementById('pdf-path').innerHTML = message; | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
var BrowserWindow = require('browser-window'); | |
var ipc = require('electron').ipcMain; | |
var shell = require('shell'); | |
module.exports.setup = function () { | |
ipc.on('print-to-pdf', function (event) { | |
var pdfPath = '/tmp/print.pdf'; | |
var win = BrowserWindow.fromWebContents(event.sender); | |
// Use default printing options | |
win.webContents.printToPDF({}, function (error, data) { | |
if (error) throw error; | |
fs.writeFile(pdfPath, data, function (error) { | |
if (error) { | |
throw error; | |
} | |
shell.openItem(pdfPath); | |
event.sender.send('wrote-pdf', pdfPath); | |
}); | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment