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 | |
| parent | bf43633560252c4b11c00cb028676d9a7b1968b8 (diff) | |
add 'save pdf' button and print opens PDF
| -rw-r--r-- | electron/src/main.js | 15 | ||||
| -rw-r--r-- | print/resources/inkstitch.js | 7 | ||||
| -rw-r--r-- | print/resources/style.css | 2 | ||||
| -rw-r--r-- | print/templates/ui.html | 1 |
4 files changed, 20 insertions, 5 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); + }) + }) +}) diff --git a/print/resources/inkstitch.js b/print/resources/inkstitch.js index 7c972c7a..57f62b1a 100644 --- a/print/resources/inkstitch.js +++ b/print/resources/inkstitch.js @@ -369,9 +369,14 @@ $(function() { $('button.print').click(function() { var pageSize = $('select#printing-size').find(':selected').text(); - electron.ipcRenderer.send('print', pageSize) + electron.ipcRenderer.send('open-pdf', pageSize) }); + $('button.save-pdf').click(function() { + var pageSize = $('select#printing-size').find(':selected').text(); + electron.ipcRenderer.send('save-pdf', pageSize) + }); + $('button.settings').click(function(){ $('#settings-ui').show(); }); diff --git a/print/resources/style.css b/print/resources/style.css index 9ffff07d..3e96e2ba 100644 --- a/print/resources/style.css +++ b/print/resources/style.css @@ -123,7 +123,7 @@ body { color: white; } - .ui button.print { + .ui button.print, .ui button.save-pdf { border: 1px solid rgb(50,132,50); } diff --git a/print/templates/ui.html b/print/templates/ui.html index 23e39145..57c17205 100644 --- a/print/templates/ui.html +++ b/print/templates/ui.html @@ -2,6 +2,7 @@ <p class="header">{{ _('Ink/Stitch Print Preview') }}</p> <div class="buttons"> <button class="print">{{ _('Print') }}</button> + <button class="save-pdf">{{ _('Save PDF') }}</button> <button class="settings">{{ _('Settings') }}</button> <button class="close">{{ _('Close') }}</button> </div> |
