2
0
mirror of https://github.com/frappe/books.git synced 2024-12-24 11:55:46 +00:00

Load printwindow in background

This commit is contained in:
Faris Ansari 2018-10-24 23:42:40 +05:30
parent c8b05140e9
commit cb731ba45f

View File

@ -27,7 +27,11 @@ async function getPDFForElectron(doctype, name, destination, htmlContent) {
const filepath = path.join(destination, name + '.pdf');
const fs = require('fs')
let printWindow = new BrowserWindow({width: 600, height: 800})
let printWindow = new BrowserWindow({
width: 600,
height: 800,
show: false
})
printWindow.loadURL(`file://${path.join(__static, 'print.html')}`);
printWindow.on('closed', () => {
@ -40,17 +44,20 @@ async function getPDFForElectron(doctype, name, destination, htmlContent) {
printWindow.webContents.executeJavaScript(code);
const printPromise = new Promise(resolve => {
printWindow.webContents.on('did-finish-load', () => {
printWindow.webContents.printToPDF({}, (error, data) => {
if (error) throw error
printWindow.close();
fs.writeFile(filepath, data, (error) => {
if (error) throw error
console.log('Write PDF successfully.')
shell.openItem(filepath);
resolve(shell.openItem(filepath));
})
})
})
})
await printPromise;
// await makePDF(html, filepath);
}