-
Notifications
You must be signed in to change notification settings - Fork 12
/
pdf.js
executable file
·35 lines (33 loc) · 1.18 KB
/
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
35
const puppeteer = require('puppeteer');
let { timeout } = require('./tools/tools.js');
(async () => {
//创建浏览器示例对象
const browser = await puppeteer.launch({
executablePath: 'chromium/Chromium.app/Contents/MacOS/Chromium',
headless: true,
args: [
'--no-sandbox',
'--disable-setuid-sandbox',
'--disable-gpu',
'--hide-scrollbars',
'--disable-web-security',
],
});
// 通过浏览器实例 Browser 对象创建页面 Page 对象
const page = await browser.newPage();
// await page.goto('https://baidu.com');
// await page.goto('http://jartto.wang');
await page.goto(
// 'https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#pdf',
'https://shensz-t.test.17zuoye.net/printer/pc/#!/class-report?from=paper-manage&group_id=34490&paper_id=a6dbefab-7a3e-4758-8476-2a824b9c1c25&session_key=e55e550587061ddd58035207997b402f',
{ waitUntil: ['domcontentloaded','networkidle0']}
);
await page.waitFor('*');
// await timeout(3000);
await page.pdf({
path: 'temp/new.pdf',
format: 'letter',
printBackground: true
});
await browser.close();
})().catch(error => console.log('error: ', error.message));