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>
在控制檯中,我能夠找到的字節數據,但沒有什麼是預覽....我錯過了什麼?
控制檯
但瀏覽器
如果可能的話, 「arraybuffer」'或' 「斑點」'設置'$ http.get()''來響應類型,使用'
另請參見[將數據URI轉換爲文件,然後附加到FormData](http://stackoverflow.com/questions/4998908/convert-data-uri-to-file-then-append-to-formdata/) – guest271314
@ guest27131 4,根據你的建議,我已經嘗試過var blob = new Blob([response.data],{type:'application/pdf'}); \t \t \t \t console.log(response.data); \t \t \t \t \t \t \t \t $ scope.content = blob;但沒有運氣..請幫助 –