大佬教程收集整理的这篇文章主要介绍了Angular2显示PDF,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我很高兴在Angular2(Typescript)或我的API中检索文件并将其流式传输.
这是我尝试在我的API中检索它但我无法弄清楚如何在Angular2中接收它并正确显示它:
public httpResponsemessage GetSOP(String partnum,String description) { var sopPath = _uow.Epicorservice.GetSOP(partnum,description).Path; httpResponsemessage result = new httpResponsemessage(httpStatusCode.oK); var stream = new FileStream(sopPath,FileMode.open); result.Content = new StreamContent(stream); result.Content.Headers.ContentType = new System.Net.http.Headers.MediaTypeHeaderValue("application/octet-stream"); return result; }
任何帮助将不胜感激.
非常感谢!!!
downloadPDF(): any { return this._http.get(url,{ responseType: ResponseContentType.blob }).map( (res) => { return new Blob([res.blob()],{ type: 'application/pdf' }) } }
然后,为了获取文件,您需要订阅它,您可以创建新的ObjectURL并使用window.open()在新选项卡中打开pDF:
this.myservice.downloadPDF().subscribe( (res) => { var fileURL = URl.createObjectURL(res); window.open(fileURL); } );
以上是大佬教程为你收集整理的Angular2显示PDF全部内容,希望文章能够帮你解决Angular2显示PDF所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。