Elzio Jr
Elzio Jr

Reputation: 73

How can I config puppeteer to get pdf page with full images and styles?

The images - 2 - and some styles - 1 - doesn't load when I use puppeteer page.pdf. Even if I set page.waitForNavigation.
enter image description here

If I use the same code with page.screenshot instead of page.pdf it works!
enter image description here


Code:

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();
})()

Upvotes: 0

Views: 1986

Answers (1)

Elzio Jr
Elzio Jr

Reputation: 73

Set printBackground param to true

await page.pdf( { path: 'test.pdf', printBackground: true } )

Upvotes: 2

Related Questions