2
0
mirror of https://github.com/frappe/books.git synced 2024-12-23 11:29:03 +00:00

Merge pull request #49 from netchampfaris/electron-pdf-2

getPDF api for electron
This commit is contained in:
Faris Ansari 2018-04-16 15:06:12 +05:30 committed by GitHub
commit 3efaf0bbfa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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
}