无法加载Pdf文档html-pdf

时间:2017-12-11 10:12:51

标签: node.js html-pdf

This是一个吸引人的链接。我使用节点运行pdfSample.jspdfsample.html是要转换为pdf的实际数据,generatepdf.html用于获取它。

当我运行它时,它显示错误Failed to load Pdf Document。我提到了this sample。我没有得到任何问题,为什么它不起作用?

    $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;
    };

1 个答案:

答案 0 :(得分:3)

您需要为实际数据而不是响应对象创建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;
    };




相关问题