mirror of
https://github.com/frappe/books.git
synced 2024-11-13 00:46:28 +00:00
Merge pull request #49 from netchampfaris/electron-pdf-2
getPDF api for electron
This commit is contained in:
commit
3efaf0bbfa
@ -2,6 +2,7 @@ const frappe = require('frappejs');
|
|||||||
const puppeteer = require('puppeteer');
|
const puppeteer = require('puppeteer');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const { shell } = require('electron');
|
||||||
const { getTmpDir } = require('frappejs/server/utils');
|
const { getTmpDir } = require('frappejs/server/utils');
|
||||||
const { getHTML } = require('frappejs/common/print');
|
const { getHTML } = require('frappejs/common/print');
|
||||||
const { getRandomString } = require('frappejs/utils');
|
const { getRandomString } = require('frappejs/utils');
|
||||||
@ -17,6 +18,13 @@ async function makePDF(html, filepath) {
|
|||||||
await browser.close();
|
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() {
|
function setupExpressRoute() {
|
||||||
if (!frappe.app) return;
|
if (!frappe.app) return;
|
||||||
frappe.app.post('/api/method/pdf', frappe.asyncHandler(handlePDFRequest));
|
frappe.app.post('/api/method/pdf', frappe.asyncHandler(handlePDFRequest));
|
||||||
@ -40,5 +48,6 @@ async function handlePDFRequest(req, res) {
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
makePDF,
|
makePDF,
|
||||||
setupExpressRoute
|
setupExpressRoute,
|
||||||
|
getPDFForElectron
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user