2
0
mirror of https://github.com/frappe/books.git synced 2025-03-21 02:22:23 +00:00

Fixed the font issue while saving pdf

Added font support for Basic Template
Added feature to select between platform safe fonts
This commit is contained in:
Piyush Singhania 2021-10-25 21:46:12 +05:30
parent a242979108
commit 91b3d969c2
3 changed files with 25 additions and 11 deletions

View File

@ -90,7 +90,13 @@ module.exports = {
{ {
fieldname: 'font', fieldname: 'font',
label: 'Font', label: 'Font',
fieldtype: 'AutoComplete', fieldtype: 'Select',
options: [
'Inter',
'Times New Roman',
'Arial',
'Courier'
],
default: 'Inter' default: 'Inter'
} }
], ],
@ -99,6 +105,7 @@ module.exports = {
'displayLogo', 'displayLogo',
'template', 'template',
'color', 'color',
'font',
'email', 'email',
'phone', 'phone',
'address', 'address',

View File

@ -1,5 +1,8 @@
<template> <template>
<div class="border h-full"> <div
class="bg-white border h-full"
:style="{ 'font-family': printSettings.font }"
>
<div> <div>
<div class="px-6 pt-6" v-if="printSettings"> <div class="px-6 pt-6" v-if="printSettings">
<div class="flex text-sm text-gray-900 border-b pb-4"> <div class="flex text-sm text-gray-900 border-b pb-4">

View File

@ -48,10 +48,10 @@ export async function loadExistingDatabase() {
filters: [{ name: 'SQLite DB File', extensions: ['db'] }] filters: [{ name: 'SQLite DB File', extensions: ['db'] }]
}; };
let { filePaths } = await remote.dialog.showOpenDialog(options); let { filePaths } = await remote.dialog.showOpenDialog(options);
if (filePaths && filePaths[0]) { if (filePaths && filePaths[0]) {
return filePaths[0] return filePaths[0];
} }
} }
@ -250,13 +250,17 @@ 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).then(data => { const sleep = m => new Promise(r => setTimeout(r, m));
printWindow.close(); (async () => {
fs.writeFile(destination, data, error => { await sleep(3000);
if (error) throw error; printWindow.webContents.printToPDF(printOptions).then(data => {
resolve(shell.openItem(destination)); printWindow.close();
fs.writeFile(destination, data, error => {
if (error) throw error;
resolve(shell.openItem(destination));
});
}); });
}); })();
}); });
}); });
} }