2017-09-19 69 views
0

圖片- 2 -和一些款式- 1 -我不使用木偶時加載page.pdf.即使我設置了page.waitForNavigation
enter image description here

如果我用的page.screenshot代替page.pdf它的工作原理相同的代碼!
enter image description here
如何配置puppeteer以獲取完整圖像和樣式的pdf頁面?

  • 節點V8.5.0
  • 木偶0.10.2(最新)


代碼:

const puppeteer = require('puppeteer'); 
const link = 'https://chrome.google.com/webstore/category/extensions?hl=pt-BR'; 
(async() => { 
    const browser = await puppeteer.launch(); 
    const page = await browser.newPage(); 
    await page.goto(link); 
    await page.waitForNavigation({timeout: 120000, waitUntil: 'networkidle', networkIdleTimeout: 3000}); 
    await page.pdf({path: 'page.pdf'}); 

    // if I remove page.pdf and change to the line below it works! 
    //await page.screenshot({fullPage: true, path: 'page.png'}); 

    browser.close(); 
})() 

回答

0

設置printBackground參數去真正

await page.pdf({ path: 'test.pdf', printBackground: true }) 
相關問題