forked from NikolaiT/scrapeulous
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pdf.js
34 lines (29 loc) · 735 Bytes
/
pdf.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
/**
* @author Nikolai Tschacher
* @version 1.0
* @last_modified Feb 2020
* @website: incolumitas.com
*
* Navigates to a url and generates a pdf from the site.
*
* https://github.com/puppeteer/puppeteer/blob/master/docs/api.md#pagepdfoptions
*
* @param.pdf_options: object, all the pdf options
*/
class Pdf extends BrowserWorker {
async crawl(url) {
await this.page.goto(url, {
waitUntil: 'networkidle0',
timeout: 40000,
});
let options = {
format: 'A4',
printBackground: true,
};
if (this.options && this.options.pdf_options) {
options = this.options.pdf_options;
}
let pdf = await this.page.pdf(options);
return Buffer.from(pdf).toString('base64')
}
}