question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Puppeteer PDF renders but missing content

See original GitHub issue

Steps to reproduce

Install Puppeteer and render a PDF as a URL from Mac OS Mojave 10.14.5. When the PDF is rendered it is missing data from what the page looks like when rendered normally in a browser.

Tell us about your environment:

  • Puppeteer version: 1.17.0
  • Platform / OS version: 10.14.5
  • Node.js version: 12.2.0 && 12.5.0

This problem does not exist when we test the same app on a Ubuntu 18.0.4 system.

What steps will reproduce the problem?

Install Puppeteer and create a PDF from an Node.js Express API endpoint.

Please include code that reproduces the issue.

await page.goto(url);
  if (data.waitFor) {
      try {
          await page.waitFor(data.waitFor)
      } catch(error) {
          throw new Error(error);
      }
  }

  const pdfBuffer = await page.pdf({
    format: 'A4',
    margin: {
      top: '20px',
      left: '20px',
      right: '20px',
      bottom: '20px',
    }
  });

  await browser.close();

What is the expected result?

The PDF should render and have all the same data on the page that shows when rendered in a browser.

What happens instead?

The PDF is rendered but text is missing. Even text from the same table shows in some columns but not in others.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:12

github_iconTop GitHub Comments

5reactions
wufeng87commented, May 22, 2020

@wuno How you solve this problem? Thanks.

0reactions
gllrm-andrescommented, Apr 16, 2022

I have separate files for the template and the styles.

everything works perfect until I needed to set the font and it wouldn’t take it using page.addStyleTag

<style>
@import url('https://fonts.googleapis.com/css2?family=Nunito:ital,wght@0,400;0,700;1,400&display=swap');
body { font-family: 'Nunito', sans-serif; }
</style>
  async generatePdf(): Promise<Buffer> {
    const browser = await puppeteer.launch();
    const page = await browser.newPage();
    const content = await this.getHtmlContent();
    await page.setContent(content, { waitUntil: 'networkidle2' });
    await page.addStyleTag({ path: this.stylesPath });
    const pdf = await page.pdf({
      printBackground: true,
      format: 'letter',
    });
    await browser.close();
    return pdf;
  }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Puppeteer PDF renders but missing content · Issue #4647
Install Puppeteer and render a PDF as a URL from Mac OS Mojave 10.14.5. When the PDF is rendered it is missing data...
Read more >
Puppeteer not rendering content on PDF (invisible text)
So, the hypothesis is that, sometimes the web font loads in time, and sometimes it does not. When it does not, the invisible...
Read more >
Puppeteer | Puppeteer
Generate screenshots and PDFs of pages. Crawl a SPA (Single-Page Application) and generate pre-rendered content (i.e. "SSR" (Server-Side Rendering)).
Read more >
Programmatically Rendering PDFs from HTML using Chrome ...
The latest solution I've found is Puppeteer. It's a Node.Js package that manipulates a headless (i.e. no browser window) version of Chrome. Chrome...
Read more >
Convert web pages into PDFs with Puppeteer and NodeJS
Generating pre-rendered content for Single Page Applications (SPAs) ... but if you are in no rush to generate the PDF, you can always...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found