-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhtml2pdf.js
46 lines (39 loc) · 1.25 KB
/
html2pdf.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const { masterToPDF } = require('relaxedjs');
const puppeteer = require('puppeteer');
const plugins = require('relaxedjs/src/plugins');
class HTML2PDF {
constructor(){
this.puppeteerConfig = {
headless: true,
args: [
'--no-sandbox',
'--disable-translate',
'--disable-extensions',
'--disable-sync'
],
};
this.relaxedGlobals = {
busy: false,
config: {},
configPlugins: [],
};
}
async _initializePlugins() {
for (let [i, plugin] of plugins.builtinDefaultPlugins.entries()) {
plugins.builtinDefaultPlugins[i] = await plugin.constructor();
}
await plugins.updateRegisteredPlugins(this.relaxedGlobals, '/');
let chrome = await puppeteer.launch(this.puppeteerConfig);
this.relaxedGlobals.puppeteerPage = await chrome.newPage();
}
async pdf(template_pug, json_data){
//await this._initPDFReader();
await masterToPDF(template_pug,
this.relaxedGlobals,
__dirname+'/knuth_temp.htm',
__dirname+'/knuth.pdf',
json_data,
);
}
}
module.exports = new HTML2PDF();