Encountered a similar situation when attempting to enable users to view and print a QR image in a new tab. This is how I accomplished it:
prepareQRForPrint(source: string) {
return "<html><head><style type='text/css' media='print'>@media print { @page { size: auto; margin: 0;} body { margin:1.6cm; } }</style><script>function step1(){\n" +
"setTimeout('step2()', 2);}\n" +
"function step2(){window.print();window.close()}\n" +
"</scri" + "pt></head><body onload='step1()'>\n" +
"<img style='width:800px;height:1000px;' src='" + source + "' /></body></html>"
}
printPreviewQR(source: string) {
let Pagelink = "about:blank";
var pwa = window.open(Pagelink, "_new");
pwa.document.open();
pwa.document.write(this.prepareQRForPrint(source));
pwa.document.close();
}
In order to use this function, you can do the following:
<a href="javascript: void(0)" (click)="printPreviewQR(QRPath)">QR-Code</a>