Node.js 无法加载Pdf文档html Pdf
是一个插销链接。我使用节点运行Node.js 无法加载Pdf文档html Pdf,node.js,html-pdf,Node.js,Html Pdf,是一个插销链接。我使用节点运行pdfSample.js,pdfSample.html是要转换为pdf的实际数据,并使用generatepdf.html获取它 当我运行它时,它显示一个错误无法加载Pdf文档。我提到过。我没有得到任何问题,为什么它不工作 $http.get(url, {responseType: 'arraybuffer'}).then(function successCallback(response){ console.log(response)
pdfSample.js
,pdfSample.html
是要转换为pdf的实际数据,并使用generatepdf.html
获取它
当我运行它时,它显示一个错误无法加载Pdf文档
。我提到过。我没有得到任何问题,为什么它不工作
$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;
};
您需要为实际数据而不是响应对象创建blob 您需要
newblob([response.data],{type:'application/pdf'})
但请确保当您点击http://localhost:8081/api/printpdf1
您得到的是pdf,而不是错误
$http.get(url,{responseType:'arraybuffer'})。然后(函数successCallback(response){
控制台日志(响应);
var file=newblob([response.data],{type:'application/pdf'});
console.log(文件);
var fileURL=URL.createObjectURL(文件);
$scope.loading=false;
q、 解析(fileURL);
},
函数errorCallback(响应){
$scope.loading=false;
q、 拒绝(回应);
});
/*.成功(功能(响应){
})
.error(函数(err){
});*/
回报承诺;
};代码>