我正在尝试从网页创建PDF。
我正在处理的应用是单页面应用程序。
我尝试了很多选项和建议,都在https://github.com/GoogleChrome/puppeteer/issues/1412上。
但是它没有起作用。
const browser = await puppeteer.launch({
executablePath: 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe',
ignoreHTTPSErrors: true,
headless: true,
devtools: false,
args: ['--no-sandbox', '--disable-setuid-sandbox']
});
const page = await browser.newPage();
await page.goto(fullUrl, {
waitUntil: 'networkidle2'
});
await page.type('#username', 'scott');
await page.type('#password', 'tiger');
await page.click('#Login_Button');
await page.waitFor(2000);
await page.pdf({
path: outputFileName,
displayHeaderFooter: true,
headerTemplate: '',
footerTemplate: '',
printBackground: true,
format: 'A4'
});
我希望的是在页面完全加载后立即生成PDF报告。
我不想写任何类型的延迟,例如 await page.waitFor(2000);
我无法使用waitForSelector,因为页面上有图表和图形,这些图表和图形是在计算后渲染出来的。
将不胜感激。