From 9fdc94bd93cada675248bb106128a07ae3340439 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Tue, 23 Oct 2018 02:21:19 +0530 Subject: [PATCH] Link bootstrap css in puppeteer for generating pdf --- server/pdf.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/server/pdf.js b/server/pdf.js index d4a9545e..bdf3aec9 100644 --- a/server/pdf.js +++ b/server/pdf.js @@ -10,6 +10,9 @@ async function makePDF(html, filepath) { const browser = await puppeteer.launch(); const page = await browser.newPage(); await page.setContent(html); + await page.addStyleTag({ + url: 'https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css' + }) await page.pdf({ path: filepath, format: 'A4' @@ -17,9 +20,9 @@ async function makePDF(html, filepath) { await browser.close(); } -async function getPDFForElectron(doctype, name, destination) { +async function getPDFForElectron(doctype, name, destination, htmlContent) { const { shell } = require('electron'); - const html = await getHTML(doctype, name); + const html = htmlContent || await getHTML(doctype, name); const filepath = path.join(destination, name + '.pdf'); await makePDF(html, filepath); shell.openItem(filepath);