-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathexport1.js
More file actions
60 lines (49 loc) · 1.9 KB
/
export1.js
File metadata and controls
60 lines (49 loc) · 1.9 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const puppeteer = require('puppeteer');
const util = require('./util.js');
const dir = './appdata';
const puppeteerParams = {
headless: true,
args: ['--no-sandbox', '--disable-setuid-sandbox']
};
function export1(path, options, callback){
util.delFiles(dir);
(async () => {
const browser = await puppeteer.launch(puppeteerParams);
const page = await browser.newPage();
await page.goto(path.sourceurl, { waitUntil: 'networkidle2' });
if (options.ext == "pdf" && options.format){
await page.pdf({
printBackground: true,
path: path.targetpath,
landscape: options.landscape,
format: options.format,
margin: {top: options.margin.top, right: options.margin.right, bottom: options.margin.bottom, left: options.margin.left },
});
}
else if (options.ext == "pdf"){
await page.pdf({
printBackground: true,
path: path.targetpath,
width : options.width,
height : options.height,
margin: {top: options.margin.top, right: options.margin.right, bottom: options.margin.bottom, left: options.margin.left },
});
}
else if (options.ext == "png") {
await page.screenshot({
path: path.targetpath,
printBackground: true,
clip : {
x : 0,
y : 0,
width : parseFloat(options.width),
height : parseFloat(options.height)
},
margin: {top: options.margin.top, right: options.margin.right, bottom: options.margin.bottom, left: options.margin.left },
});
}
callback();
browser.close();
})();
}
module.exports = export1;