Fix print to pdf functionality

This commit is contained in:
Janosch Maier 2022-01-11 22:15:43 +01:00 committed by Ben Gotow
parent 2591fc7ff3
commit 3be72eee5c
2 changed files with 5 additions and 10 deletions

View file

@ -80,6 +80,7 @@ export default class PrintWindow {
contextIsolation: false,
},
});
require("@electron/remote").require("@electron/remote/main").enable(this.browserWin.webContents);
this.browserWin.removeMenu();
fs.writeFileSync(tmpMessagesPath, `window.printMessages = ${printMessages}`);
fs.writeFileSync(this.tmpFile, content);

View file

@ -7,7 +7,7 @@ win.addListener('page-title-updated', event => {
});
global.printToPDF = async () => {
const { filePath } = awaitrequire('@electron/remote').dialog.showSaveDialog({
const { filePath } = await require('@electron/remote').dialog.showSaveDialog({
defaultPath: `${win.getTitle()}.pdf`,
});
@ -20,14 +20,8 @@ global.printToPDF = async () => {
pageSize: 'Letter',
printBackground: true,
landscape: false,
},
(error, data) => {
if (error) {
require('@electron/remote').dialog.showErrorBox('An Error Occurred', `${error}`);
return;
}
fs.writeFileSync(filename, data);
}).then(data => {
fs.writeFileSync(filePath, data);
}
);
);
};