kopia lustrzana https://github.com/inkstitch/inkstitch
add 'save pdf' button and print opens PDF
rodzic
bf43633560
commit
09c46e0fb4
|
@ -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');
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
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);
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
|
|
|
@ -123,7 +123,7 @@ body {
|
|||
color: white;
|
||||
}
|
||||
|
||||
.ui button.print {
|
||||
.ui button.print, .ui button.save-pdf {
|
||||
border: 1px solid rgb(50,132,50);
|
||||
}
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
|
Ładowanie…
Reference in New Issue