I need to print a pdf blob using typescript. I've tried the following code, which works in Chrome but not in Edge.
Code 1 (works in Chrome but prints blank in Edge) -
const fileURL = URL.createObjectURL(blob);
const iframe = document.createElement('iframe');
iframe.style.display = 'none';
iframe.src = fileURL;
iframe.name = fileName;
document.body.appendChild(iframe);
iframe.contentWindow.print();
Code 2 (works in Chrome but throws error for contentWindow.document being null) -
const fileURL = URL.createObjectURL(blob);
const iframe = document.createElement('iframe');
iframe.style.display = 'none';
iframe.src = fileURL;
iframe.name = fileName;
document.body.appendChild(iframe);
document.getElementsByTagName('iframe')[0].contentWindow.document.execCommand('print', false, null)
I have searched for solutions but haven't found any satisfying answers. Since I'm using Angular 6, is there a more direct method or library that can achieve this?