【发布时间】:2016-06-23 16:24:12
【问题描述】:
我有从服务器获取 pdf 数据的 angular 函数:
printDocument: function (bundleId, policyId) {
var fileName = "test.pdf";
var a = document.createElement("a");
document.body.appendChild(a);
a.style = "display: none";
$resource(baseUrlPrint, {
bundleId: bundleId,
policyId: policyId
}, {
get: {
method: 'GET'
},
responseType:'arraybuffer',
cache: true
}).get().$promise.then(function(result) {
console.log(result);
var file = new Blob([result], {type: 'application/pdf'});
var fileURL = (window.URL || window.webkitURL).createObjectURL(file);
a.href = fileURL;
a.download = fileName;
a.click();
});
}
当我检查 result 变量时,我看到字节数组包含 pdf 文件。但是当我在 Notepad++ 中打开这个文件时,我看到没有 pdf 字节数据,只有: [对象对象]。我的 Blob 对象有问题吗?
【问题讨论】:
标签: angularjs pdf download blob