spiritix / php-chrome-html2pdf

A PHP library for converting HTML to PDF using Google Chrome
MIT License
112 stars 29 forks source link

printBackground: true not working for header and footer #17

Closed ngajhede closed 4 years ago

ngajhede commented 4 years ago

Hiya,

When setting a background color in the imported header and footer, it is not showing when generating a PDF. I tried using the printBackground: true option, but to no luck.

What eventually worked was using the CSS rule -webkit-print-color-adjust: exact.

Is this expected behavior? Does the rule only apply for the main content?

spiritix commented 4 years ago

Hello, That's intended behavior. From the Puppeteer documentation:

page.pdf() generates a pdf of the page with print css media. [...] NOTE By default, page.pdf() generates a pdf with modified colors for printing. Use the -webkit-print-color-adjust property to force rendering of exact colors.

I will update the documentation accordingly.