Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 无法加载Pdf文档html Pdf_Node.js_Html Pdf - Fatal编程技术网

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){
});*/
回报承诺;
};