Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
268 views
in Technique[技术] by (71.8m points)

javascript - read the pdf and display in IE,

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...