I'm using angular 4 and need a user to be able to print a section of data. I can get a print preview with bootstrap working just fine, however, no color shows up whatsoever when I show the preview. I've gotten this same result in chrome and safari, and even with the background colors checked on in safari, the colors still don't show up.
The left side of the screenshot is what color is supposed to show up, the right is what the print preview shows.
I also found that the same thing happens with just the regular application itself when I right click and select print. Other websites show up totally fine with color in print preview.
This is my print function (which right now is pretty much pulled from another stack overflow question, I plan on changing this later.)
print(): void {
let printContents, popupWin;
printContents = document.getElementById('print-section').innerHTML;
popupWin = window.open('', '_blank', 'top=0,left=0,height=100%,width=auto');
popupWin.document.open();
popupWin.document.write(`
<html>
<head>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<title>Print tab</title>
<style>
.lightBlue {
background-color: lightblue !important;
}
@media print {
.lightBlue {
background-color: lightblue !important;
-webkit-print-color-adjust: exact;
}
}
</style>
</head>
<body onload="window.print();window.close()">${printContents}</body>
</html>`
);
popupWin.document.close();
}
This is the HTML is being displayed in the print window:
<div id="print-section" [hidden]="printable">
<div class="container">
<h1>Location Report for {{showOnly}}s</h1>
<br/>
<table class="table table-bordered">
<thead class="lightBlue">
<tr>
<th >Dog</th>
<th>Location</th>
</tr>
</thead>
<tbody>
<tr>
</tr>
</tbody>
</table>
</div>
</div>
I've tried so many solutions on stack overflow and I haven't got any of them to work, so I'm kind of at a loss at this point.