如何在angularjs中读取pdf流 [英] How to read pdf stream in angularjs
本文介绍了如何在angularjs中读取pdf流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从服务器获得了以下 PDF 流:
I got the following PDF stream from a server:
如何在 AngularJS 中读取这个流?我尝试使用以下代码在新窗口中将其作为 PDF 文件打开:
How can this stream be read in AngularJS? I tried to open this as a PDF file in a new window by using the following code:
.success(function(data) {
window.open("data:application/pdf," + escape(data));
});
但是我无法在打开的窗口中看到内容.
But I'm unable to see the content in opened window.
推荐答案
我通过更改控制器代码实现了这一点
I achieved this by changing my controller code
$http.get('/retrievePDFFiles', {responseType: 'arraybuffer'})
.success(function (data) {
var file = new Blob([data], {type: 'application/pdf'});
var fileURL = URL.createObjectURL(file);
window.open(fileURL);
});
这篇关于如何在angularjs中读取pdf流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文