How to read pdf stream in angularjs
I achieved this by changing my controller code
$http.get('/retrievePDFFiles', {responseType: 'arraybuffer'}) .success(function (data) { var file = new Blob([data], {type: 'application/pdf'}); var fileURL = URL.createObjectURL(file); window.open(fileURL); });
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:
<div ng-controller="PDFController" class="modal fade" id="pdfModal" tabindex="-1" role="dialog" aria-hidden="true"><div class="modal-dialog modal-lg"> <div class="modal-content" onloadstart=""> <object data="{{pdfContent}}" type="application/pdf" style="width:100%; height:1000px" /> </div></div>
Also you can go with the Angular ng-pdfviewer and view your pdf by using it's js files.
Have a look at PDF.JS. This is a client side javascript library that can fetch a pdf stream and render it client side. Angular is unable to read a pdf so this isn't an angular issue.