阅读pdf并在IE中显示,

时间:2017-06-28 16:42:59

标签: javascript java angularjs spring-mvc pdf

我想使用java和angularjs阅读并显示存储在localdrive中的PDF,并且应该在IE和Chrome中工作。

以下代码适用于Chrome,但不适用于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];
    }

使用上面的java代码,我可以读取PDF并成功显示在chrome中。但它不能在internetExplorer中工作。如何使上述代码在IE中工作。

0 个答案:

没有答案