mirror of
https://github.com/frappe/books.git
synced 2025-02-02 12:08:27 +00:00
Pdf for electron
This commit is contained in:
parent
f7db1206b0
commit
a30fb50405
@ -15,6 +15,14 @@ module.exports = class PrintPage extends Page {
|
|||||||
this.addButton(frappe._('Edit'), 'primary', () => {
|
this.addButton(frappe._('Edit'), 'primary', () => {
|
||||||
frappe.router.setRoute('edit', this.doctype, this.name)
|
frappe.router.setRoute('edit', this.doctype, this.name)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.addButton(frappe._('Print'), 'secondary', async () => {
|
||||||
|
const pdf = require('frappejs/server/pdf');
|
||||||
|
const savePath = '/Users/farisansari/frappe.pdf';
|
||||||
|
pdf(await this.getHTML(true), savePath);
|
||||||
|
const { shell } = require('electron');
|
||||||
|
shell.openItem(savePath);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async show(params) {
|
async show(params) {
|
||||||
@ -29,18 +37,28 @@ module.exports = class PrintPage extends Page {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async renderTemplate() {
|
async renderTemplate() {
|
||||||
this.printFormat = await frappe.getDoc('PrintFormat', this.meta.print.printFormat);
|
|
||||||
let doc = await frappe.getDoc(this.doctype, this.name);
|
|
||||||
let context = {doc: doc, frappe: frappe};
|
|
||||||
|
|
||||||
frappe.desk.setActiveDoc(doc);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.body.innerHTML = `<div class="print-page">${nunjucks.renderString(this.printFormat.template, context)}</div>`;
|
this.body.innerHTML = await this.getHTML();
|
||||||
// this.setTitle(doc.name);
|
// this.setTitle(doc.name);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.renderError('Template Error', e);
|
this.renderError('Template Error', e);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getHTML(pdf = false) {
|
||||||
|
this.printFormat = await frappe.getDoc('PrintFormat', this.meta.print.printFormat);
|
||||||
|
let doc = await frappe.getDoc(this.doctype, this.name);
|
||||||
|
let context = {doc: doc, frappe: frappe};
|
||||||
|
frappe.desk.setActiveDoc(doc);
|
||||||
|
return `
|
||||||
|
${pdf ? `
|
||||||
|
<style>
|
||||||
|
${require('fs').readFileSync('./www/dist/css/style.css').toString()}
|
||||||
|
</style>
|
||||||
|
` : ''}
|
||||||
|
<div class="print-page">
|
||||||
|
${nunjucks.renderString(this.printFormat.template, context)}
|
||||||
|
</div>`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user