2
0
mirror of https://github.com/frappe/books.git synced 2024-11-10 07:40:55 +00:00

getPDF api for electron

This commit is contained in:
Faris Ansari 2018-04-16 15:02:31 +05:30
parent e153971713
commit 4471bc0bd1

View File

@ -2,6 +2,7 @@ const frappe = require('frappejs');
const puppeteer = require('puppeteer');
const fs = require('fs');
const path = require('path');
const { shell } = require('electron');
const { getTmpDir } = require('frappejs/server/utils');
const { getHTML } = require('frappejs/common/print');
const { getRandomString } = require('frappejs/utils');
@ -17,6 +18,13 @@ async function makePDF(html, filepath) {
await browser.close();
}
async function getPDFForElectron(doctype, name) {
const html = await getHTML(doctype, name);
const filepath = path.join(frappe.electronConfig.directory, name + '.pdf');
await makePDF(html, filepath);
shell.openItem(filepath);
}
function setupExpressRoute() {
if (!frappe.app) return;
frappe.app.post('/api/method/pdf', frappe.asyncHandler(handlePDFRequest));
@ -40,5 +48,6 @@ async function handlePDFRequest(req, res) {
module.exports = {
makePDF,
setupExpressRoute
setupExpressRoute,
getPDFForElectron
}