Node- v8.11.1无头Chrome
我试图生成PDF,但不知何故,背景图像没有在PDF中捕获。
下面是代码。任何帮助表示赞赏
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch({headless: true});
const page = await browser.newPage();
await page.goto('http://54.201.139.151/', {waitUntil : 'networkidle0'});
await page.pdf({path: 'hn40.pdf', printBackground: true, width: '1024px' , height: '768px'});
await browser.close();
})();
答案 0 :(得分:2)
正如Rippo所说,you require page.emulateMedia("screen")
可以使其正常运作。我已在下面更新了您的脚本,但我将页面更改为谷歌进行测试。
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('http://google.ca/', {waitUntil : 'networkidle2'});
await page.emulateMedia('screen');
await page.pdf({path: 'hn40.pdf', printBackground: true, width: '1024px' , height: '768px'});
await browser.close();
})();
答案 1 :(得分:0)
更新:page.emulateMedia()
被page.emulateMediaType()
取代