How to read pdf stream in angularjs

后端 未结 5 452
[愿得一人]
[愿得一人] 2020-12-01 06:32

I got the following PDF stream from a server: \"PDF

How can this stream be read in AngularJS? I tried

5条回答
  •  伪装坚强ぢ
    2020-12-01 07:10

    The problem with using config.responseType is that the $http service still runs the default responseTransformer and attempts to convert the response to JSON. Also, you are sending the default accept headers. Here is an (untested) alternative:

    $http.get('/retrievePDFFiles', {
        headers: { Accept: "application/pdf"},  
        transformResponse: function(data) {
            return new Blob([data], {type: 'application/pdf'});
        }}).success(function (data) {
               var fileURL = URL.createObjectURL(data);
               window.open(fileURL);
        });
    

提交回复
热议问题