mirror of
https://github.com/frappe/books.git
synced 2024-12-23 11:29:03 +00:00
32cd6581d1
- /api/method/pdf - frappe.getPDF - download using blob url
30 lines
675 B
JavaScript
30 lines
675 B
JavaScript
const frappe = require('frappejs');
|
|
const nunjucks = require('nunjucks/browser/nunjucks');
|
|
|
|
async function getHTML(doctype, name) {
|
|
const meta = frappe.getMeta(doctype);
|
|
const printFormat = await frappe.getDoc('PrintFormat', meta.print.printFormat);
|
|
let doc = await frappe.getDoc(doctype, name);
|
|
let context = {doc: doc, frappe: frappe};
|
|
|
|
console.log(context);
|
|
|
|
let html;
|
|
try {
|
|
html = nunjucks.renderString(printFormat.template, context);
|
|
} catch (error) {
|
|
console.log(error);
|
|
html = '';
|
|
}
|
|
|
|
return `
|
|
<div class="print-page">
|
|
${html}
|
|
</div>
|
|
`;
|
|
}
|
|
|
|
module.exports = {
|
|
getHTML
|
|
}
|