I have been trying for a couple of weeks now to print a label using angular. I am able to get the label to print with no issues. The issue is it loses the formatting of the label in the preview print and also printing. I have tried a lot of the code floating around and no matter which function I run the HTML through I get the same results. I have also tried a combo of the .ts, .html, and scss.component. The code is below on what is working now to the point it needs to print. Also to note this is a modal pop up.
printDiv(): void {
var divContents = document.getElementById("GFG").innerHTML;
var a = window.open('', '', 'height=500, width=500');
a.document.write('<html>');
a.document.write('<body > <h1>Div contents are <br>');
a.document.write(divContents);
a.document.write('</body></html>');
a.document.close();
a.print();
}
@media print {
body * {
visibility: hidden;
}
#section-to-print, #section-to-print * {
visibility: visible;
}
#section-to-print {
position: absolute;
left: 0;
top: 0;
}
}
<div id="GFG" class="divTable">
<div class="divTableBody">
<div class="divTableRow">
<div class="divTableCell">
<br />
<scl-ngx-qrcode [text]="qrCodeString" [options]="options"></scl-ngx-qrcode>
<br />
</div>
<div class="divTableCell">
<h4 class="text-center">COC: 23456</h4>
<div>{{ CompanyName }}</div>
<div>{{ AddressLine1 }}</div>
<div>{{ AddressLine2 }}</div>
<div>{{ City }}, {{ PostalCode }}</div>
<div>{{ PhoneNumber }}
<div>{{ PrjCode }}</div>
</div>
<div class="divTableRow">
<div class="divTableCell">
<h1 class="display-2 text-center">RUSH</h1>
<br/>
Container _____ of _____
<br/>
</div>
<div class="divTableCell"> </div>
</div>
</div>
</div>
<button (click)="printDiv()">Print Label(s)</button>