Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I force phantomjs to render pdf's with the background images and colors

Tags:

phantomjs

Using phantom JS 1.9.7 I am having issues printing my webpage to PDF.

Instead of matching the page exactly, background colors and images are stripped, as per: How can I force browsers to print background images in CSS?

like image 739
Jason Avatar asked Feb 23 '14 04:02

Jason


1 Answers

Thanks to a post on another question, here is the answer:

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

You can add the CSS style "-webkit-print-color-adjust: exact;" to the element to force print the background color and/or image.

See the documentation: https://developer.mozilla.org/en-US/docs/Web/CSS/-webkit-print-color-adjust

Odd how this is on MDN.

like image 164
Jason Avatar answered Sep 29 '22 10:09

Jason