node-html-pdf icon indicating copy to clipboard operation
node-html-pdf copied to clipboard

background-color property is not working

Open rbgpt opened this issue 7 years ago • 17 comments

rbgpt avatar Nov 19 '18 11:11 rbgpt

I had similar case with yours. My solution is to add a new selector that pinpoint to the element you want to style. Not its parent, but the element itself. Forget about inheritance when it comes to background-color and color in html-pdf.

dorklord23 avatar Dec 06 '18 03:12 dorklord23

@dorklord23 can you clarify that with an example? I am not using any inheritance and styling a div directly, yet background-color is completely ignored.

adamreisnz avatar Apr 29 '19 01:04 adamreisnz

Faced similar issue, fixed it by giving the html element inline style <div style="background:#007bff;">

narendra315 avatar Jun 27 '19 10:06 narendra315

The above does not work for me.

stormfar avatar Jul 04 '19 12:07 stormfar

Try this in your css file

@media print
{
  .body {
    background: #00BAFF;
  }
}

dangear avatar Sep 23 '19 08:09 dangear

After trying this again, I discovered that adding !important worked for me, with the class selector solution. Did not need @media print.

stormfar avatar Sep 30 '19 09:09 stormfar

@media print nor adding !important are working here. Using bootstrap and trying to use the .table-striped css class.

jnaklaas avatar Oct 30 '20 09:10 jnaklaas

@jnaklaas did you find solution?

softmantk avatar Nov 04 '20 17:11 softmantk

@softmantk no I haven't.

jnaklaas avatar Nov 05 '20 08:11 jnaklaas

I had similar case with yours. My solution is to add a new selector that pinpoint to the element you want to style. Not its parent, but the element itself. Forget about inheritance when it comes to background-color and color in html-pdf.

This worked for me.

softmantk avatar Nov 20 '20 06:11 softmantk

Adding html { -webkit-print-color-adjust: exact; } in my css worked for me.

ThibaudREY avatar Jun 29 '21 13:06 ThibaudREY

@ThibaudREY thanks it worked for me I didn't know the existence of color-adjust CSS property I was struggling with another issue where background color and image color weren't the same

damienbry avatar Sep 28 '21 19:09 damienbry

@marcbachmann i suggest you mark this issue resolved as the solution provided by @ThibaudREY works perfectly. And update your documentation accordingly. Now I love this package! 👍

dlamprey avatar Apr 01 '22 15:04 dlamprey

@ThibaudREY only this worked for me

sarunmrzn avatar Jul 21 '22 08:07 sarunmrzn

I actually managed to resovle this by passing in printBackground: true into the options object. From the docs.. "printBackground - Print background graphics. Defaults to false."

latchy avatar Sep 27 '22 04:09 latchy

Adding html { -webkit-print-color-adjust: exact; } in my css worked for me.

Thanks for this, the only solution that really worked for me!!

htorohn avatar Dec 16 '22 21:12 htorohn