这是柱塞连接。我使用节点运行pdfSample.js,pdfsample.html是转换成pdf的实际数据,generatepdf.html是用来获取它的。
当我运行它时,它会显示一个错误Failed to load Pdf Document。我反驳了这个样本。我不明白为什么它不起作用?
$http.get(url, {responseType: 'arraybuffer'}).then(function successCallback(response){
console.log(response);
var file = new Blob([response], {type: 'application/pdf'});
console.log(file);
var fileURL = URL.createObjectURL(file);
$scope.loading = false;
q.resolve(fileURL);
},
function errorCallback(response){
$scope.loading = false;
q.reject(response);
});
/* .success(function (response) {
})
.error(function (err) {
});*/
return q.promise;
};发布于 2017-12-15 12:31:09
您需要为实际数据创建blob,而不是响应对象。
你需要new Blob([response.data], {type: 'application/pdf'})
但要确保当你点击http://localhost:8081/api/printpdf1,你得到的pdf,而不是一个错误。
$http.get(url, {responseType: 'arraybuffer'}).then(function successCallback(response){
console.log(response);
var file = new Blob([response.data], {type: 'application/pdf'});
console.log(file);
var fileURL = URL.createObjectURL(file);
$scope.loading = false;
q.resolve(fileURL);
},
function errorCallback(response){
$scope.loading = false;
q.reject(response);
});
/* .success(function (response) {
})
.error(function (err) {
});*/
return q.promise;
};
https://stackoverflow.com/questions/47750561
复制相似问题