0

My software creates an HTML document with CSS, just to convert it to PDF afterwards (JS: window.print()). The generated PDF ignores CSS background colors, probably to save ink - but I don't want that. I want to have my document printed exactly the way it looks naturally. I know I could modify the print by using a @media print, but as I have lots of inline CSS in my code now, that would be horrible to implement. Is there an elegenat way to put some kind of flag in my document, so that the window.print() doesn't modify anything?

Maybe some kind of @media print of pure ignorance?


The duplicate solved it, just put this in the head-style and it works:

@media print {
 * {
  -webkit-print-color-adjust: exact; 
 } 
}
d0n.key
  • 1,318
  • 2
  • 18
  • 39
  • Can't you simply include all of your css code inside the @media print {} ? That would do the work – mindmaster Feb 21 '19 at 15:15
  • There is no way to do this programatically as they are browser settings, unless you convert the page to a pdf and print it like that (I think you can print background colours and images in that) – Pete Feb 21 '19 at 15:15
  • 1
    Although [this post](https://stackoverflow.com/questions/21854510/unable-to-print-background-colors-css-solution) seems to think you can print background colours in webkit browsers – Pete Feb 21 '19 at 15:17

0 Answers0