【发布时间】:2026-01-07 12:55:01
【问题描述】:
我是 javascript 和网络编程的初学者 我正在使用节点创建一个 pdf 文件并将其作为 http 响应通过管道传输
在客户端,我使用 angularjs 从响应中创建 blob。 我没有得到正确的 pdf 文件,而是得到一个带有空白页的 pdf 页面。 我是否以错误的方式创建了 blob?有什么我错过的吗?
我确实尝试研究互联网,我发现最接近的是: AngularJS: Display blob (.pdf) in an angular app
但我按照说明操作后仍然无法正常工作
我的代码:
$http.get('pdf-page', null, { responseType: 'arraybuffer' })
.success(function (res) {
console.log(res);
var file = new Blob([data], {type: 'application/pdf'});
var fileURL = URL.createObjectURL(file);
window.open(fileURL);
});
console.log(res) 的结果:
%PDF-1.3 %���� 5 0 obj
endobj 4 0 obj
endobj 7 0 obj
【问题讨论】:
-
原来我给 $http.get 错误的论据链接到解决方案:[*.com/questions/28093736/… [1]:*.com/questions/28093736/…
标签: javascript angularjs pdf blob