无法加载PDF文档HTML-PDF



这是一个plunker链接。我使用节点运行pdfSample.jspdfsample.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;
    };

您需要将斑点创建为实际数据而不是响应对象。

您需要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;
    };

最新更新