vedika shrivas
vedika shrivas

Reputation: 333

Failed to load Pdf Document html-pdf

This is a plunker link. I run pdfSample.js using node, pdfsample.html is actual data to convert into pdf and generatepdf.html is used to fetch it .

When i run it, it shows me an error Failed to load Pdf Document. I reffered this sample. I am not getting any issue why it is not working?

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

Upvotes: 1

Views: 5351

Answers (1)

Alex Michailidis
Alex Michailidis

Reputation: 4143

You need to create the blob to the actual data not the response object.

You need new Blob([response.data], {type: 'application/pdf'})

But make sure that when you hit http://localhost:8081/api/printpdf1 you get the pdf and not an error.

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

Upvotes: 3

Related Questions