我需要的是从后端生成的pdf文件,以便在打印模式下的新选项卡中显示。我实现了一个适用于FF但不适用于IE的解决方案。可能有一些' hack'为IE工作?
Service.downloadPdf(inputObject, scope.reportType).then(function (data) {
var file = new Blob([data.data], {type: 'application/pdf'}); //pdf
var pdfUrl = URL.createObjectURL(file);
var printwWindow = $window.open(pdfUrl);
printwWindow.print();
});
我只能看到IE的控制台错误:
TypeError: Unable to get property 'print' of undefined or null reference
答案 0 :(得分:-1)
then(function (data) {
var blob = new Blob([data.blob()], { type: 'application/pdf' });
const blobUrl = URL.createObjectURL(blob);
const iframe = document.createElement('iframe');
iframe.style.display = 'none';
iframe.src = blobUrl;
document.body.appendChild(iframe);
iframe.contentWindow.print();
}