2017-04-19 63 views
0

我正在嘗試在AngularJS應用程序中預覽PDF文檔。如何在AngularJS應用程序中預覽PDF文件?

從我的Web API,我送的字節

[Route("PdfData")] 
     [HttpGet] 
     public byte[] GetPdfData() 
     { 
      BlobService bs = new BlobService(); 
      var blobPdfContent = bs.PdfRecordsInBytes("Sample.pdf"); 
      return blobPdfContent; 
     } 

我angularJS代碼是根據

<html> 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> 
<body> 

    <div ng-app="myApp" ng-controller="myCtrl"> 


     <embed ng-src="{{content}}" style="width:200px;height:200px;"></embed> 

    </div> 

    <script> 
     var app = angular.module('myApp', []); 
     app.controller('myCtrl', [ '$scope', '$sce','$http',function($scope,$sce,$http) { 

      $http.get("http://localhost:67845/PdfData") 
      .then(function(response) { 
       console.log(response.data);      
        $scope.content = $sce.trustAsResourceUrl(response.data); 
       }); }]); 
    </script> 

</body> 
</html> 

在控制檯中,我能夠找到的字節數據,但沒有什麼是預覽....我錯過了什麼?

控制檯

enter image description here

但瀏覽器

enter image description here

+0

如果可能的話, 「arraybuffer」'或' 「斑點」'設置'$ http.get()''來響應類型,使用'