How to read pdf stream in angularjs

后端 未结 5 461
[愿得一人]
[愿得一人] 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:09

    Pleas have a look on the following code:

    On Controller Side -

    $http.get(baseUrl + apiUrl, { responseType: 'arraybuffer' })
              .success(function (response) {                  
                 var file = new Blob([response], { type: 'application/pdf' });
                 var fileURL = URL.createObjectURL(file);
                 $scope.pdfContent = $sce.trustAsResourceUrl(fileURL);
               })
               .error(function () {                        
               });
    

    On HTML Side: