k h*_*ish 11 javascript pdf angular
我尝试使用window.open()打开PDF文件,但窗口会自动打开和关闭,文件会像任何其他文件一样下载.如何在新标签页中打开PDF文件?FYI没有安装广告拦截器
k h*_*ish 26
感谢您的答复.
从@barbsan的想法,我改变了http标题并收到了一个blob并使用它来使用window.open()将blob显示为pdf.有效.
这是我的示例代码.
在服务文件中
downloadPDF(url): any {
    const options = { responseType: ResponseContentType.Blob  };
    return this.http.get(url, options).map(
    (res) => {
        return new Blob([res.blob()], { type: 'application/pdf' });
    });
  }
在组件文件中
this.dataService.downloadPDF(url).subscribe(res => {
  const fileURL = URL.createObjectURL(res);
  window.open(fileURL, '_blank');
});
| 归档时间: | 
 | 
| 查看次数: | 19283 次 | 
| 最近记录: |