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.

Page.pdf - Colors rendering

See original GitHub issue

When I run my page in headless mode every colors is rendered right. But when I get the pdf with page.pdf() with no options some colors (a few in fact) are wrong - too bright or too dark - Is there any reason for this?

update: I solved this with this css (not sure why it wasn’t working without it)

html {
  -webkit-print-color-adjust: exact;
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:146
  • Comments:18 (5 by maintainers)

github_iconTop GitHub Comments

10reactions
cage1618commented, Jun 13, 2020
await page.addStyleTag({
  content: `
    html {
      -webkit-print-color-adjust: exact !important;
      -webkit-filter: opacity(1) !important;
    }
  `
});

This worked for me, -webkit-filter item is required

3reactions
kaveetcommented, Jun 21, 2018

Thanks for sharing your solution–that wasn’t a fun problem to debug.

The color changes appear to be part of the browser’s strategy for reducing print cost and achieving more accurate colors on paper. It’s part of the browser’s printing functionality, which is why the colors only change when using page.pdf() as opposed to opening the page in a browser. This isn’t really a problem with Puppeteer but really should be somewhere in its documentation.

You can read more about this here: https://drafts.csswg.org/css-color-4/#color-adjust

Read more comments on GitHub >

github_iconTop Results From Across the Web

Color conversion and ink management (Acrobat Pro)
Convert document colors · In the Convert Colors dialog box, select a conversion command. · Specify the conversion profile. · Select the rendering...
Read more >
Render-as PDF: Where'd the colors go? - Salesforce Developers
The background colors render fine in HTML but are absent in PDF. ... WITHOUT the page attribute 'render-as="pdf",' the colors render as I'd ......
Read more >
Puppeteer not rendering color, background color when I try to ...
js and HTML template code which creates a PDF from an HTML template. It's not putting in the colors. const puppeteer = require('puppeteer');...
Read more >
Acrobat Pro does not render PDF colors correctly on screen
Acrobat Pro (tried 8 and 7) does not render colors correctly on screen ... 2004 and Pages 3.0.2. but e.g. FreeHand MX PDFs...
Read more >
PDF color rendered incorrectly - Google Chrome Community
Hi Guys, I found an issue when I open a PDF via Chrome browser, the color or the first page rendered incorrectly.
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