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

format document

This commit is contained in:
Ankit Singhaniya 2021-08-18 23:29:13 +05:30 committed by 18alantom
parent fd8221a576
commit 87c944cd4f
2 changed files with 10 additions and 11 deletions

View File

@ -1 +1 @@
import './styles/index.css'; import './styles/index.css';

View File

@ -209,9 +209,9 @@ export function handleErrorWithDialog(e, doc) {
// NOTE: a hack to find all the css from the current document and inject it to the print version // NOTE: a hack to find all the css from the current document and inject it to the print version
// remove this if you are able to fix and get the default css loading on the page // remove this if you are able to fix and get the default css loading on the page
function injectCSS(contents) { function injectCSS(contents) {
const styles = document.getElementsByTagName('style') const styles = document.getElementsByTagName('style');
for(let style of styles) { for (let style of styles) {
contents.insertCSS(style.innerHTML); contents.insertCSS(style.innerHTML);
} }
} }
@ -259,14 +259,13 @@ export function makePDF(html, destination) {
return new Promise(resolve => { return new Promise(resolve => {
printWindow.webContents.on('did-finish-load', () => { printWindow.webContents.on('did-finish-load', () => {
injectCSS(printWindow.webContents); injectCSS(printWindow.webContents);
printWindow.webContents.printToPDF(printOptions) printWindow.webContents.printToPDF(printOptions).then(data => {
.then(data => { printWindow.close();
printWindow.close(); fs.writeFile(destination, data, error => {
fs.writeFile(destination, data, error => { if (error) throw error;
if (error) throw error; resolve(shell.openItem(destination));
resolve(shell.openItem(destination)); });
}); });
})
}); });
}); });
} }