diff options
| author | Lex Neva <github.com@lexneva.name> | 2019-04-18 10:15:13 -0400 |
|---|---|---|
| committer | Lex Neva <github.com@lexneva.name> | 2019-04-18 10:15:13 -0400 |
| commit | 09c46e0fb499987899a2e67819099eba2c121487 (patch) | |
| tree | db2144e828951536d3ea76b57afaa981ea679fd6 /electron | |
| parent | bf43633560252c4b11c00cb028676d9a7b1968b8 (diff) | |
add 'save pdf' button and print opens PDF
Diffstat (limited to 'electron')
| -rw-r--r-- | electron/src/main.js | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/electron/src/main.js b/electron/src/main.js index 210e26ed..db52ac94 100644 --- a/electron/src/main.js +++ b/electron/src/main.js @@ -1,4 +1,4 @@ -import { app, BrowserWindow, ipcMain, dialog } from 'electron'; +import { app, BrowserWindow, ipcMain, dialog, shell } from 'electron'; var fs = require('fs'); var path = require('path') var tmp = require('tmp') @@ -43,11 +43,20 @@ app.on('window-all-closed', () => { app.quit(); }); -ipcMain.on('print', function (event, pageSize) { +ipcMain.on('save-pdf', function (event, pageSize) { mainWindow.webContents.printToPDF({"pageSize": pageSize}, function(error, data) { dialog.showSaveDialog(mainWindow, {"defaultPath": "inkstitch.pdf"}, function(filename, bookmark) { if (typeof filename !== 'undefined') fs.writeFileSync(filename, data, 'utf-8'); }) }) -})
\ No newline at end of file +}) + +ipcMain.on('open-pdf', function (event, pageSize) { + mainWindow.webContents.printToPDF({"pageSize": pageSize}, function(error, data) { + tmp.file({keep: true, discardDescriptor: true}, function(err, path, fd, cleanupCallback) { + fs.writeFileSync(path, data, 'utf-8'); + shell.openItem(path); + }) + }) +}) |
