I want to read and display the PDF stored in localdrive using java and angularjs and should work in IE and chrome.
Below code works in Chrome but not in IE.
html
<div class="tab-content" ng-controller="pdfViewController" style="max-height: 600px; overflow:hidden">
<div ng-bind-html="trustedHtml" style="width: 100%; height: 600px;"></div>
</div>
js code:
app.controller('pdfViewController', function ($rootScope, $scope, $sce, MyPDFService, $window) {
$scope.content = {};
MyPDFService.getPDFReport().then(
function (response) {
$scope.content = response;
$scope.trustedHtml = $sce.trustAsHtml($scope.content);
},
function (errResponse) {
$rootScope.showError("Internal error" + errResponse);
});
});
_myPDFServiceFactory.getPDFReport = function(){
var deferred = $q.defer();
var repUrl = appURL+'/myReports'+'/getPDFReport.form';
$http.get(repUrl,{responseType:'blob'})
.then(
function (response) {
deferred.resolve(response.data);
},
function(errResponse){
console.error('Error'+errResponse);
deferred.reject(errResponse);
}
);
return deferred.promise;
}
javacode:
@RequestMapping(value = "/getPDFReport", method = RequestMethod.GET, produces = "application/octet-stream")
@ResponseBody public byte[] showPDFReport(final HttpServletResponse response) {
try {
File file = new File("C:/reports/myDataReport.pdf");
return org.apache.commons.io.FileUtils.readFileToByteArray(file);
} catch (Exception e) {
System.out.println("Exception while reading file" + e);
}
return new byte[0];
}
With above java code,i could able to read the PDF and display in chrome successfully. However its not working in internetExplorer. How to make the above code work in IE.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…