angularjs - Download File PDF in Angular from Spring MVC -
i have situation. in angularjs:
var graphhtml = $(".element10")[0]; $http({ method: 'post', url: '/export/pdf', data: "html=" + graphhtml.outerhtml, headers: {'content-type': 'application/x-www-form-urlencoded'} }).success(function(data, status, headers, config) { var hiddenelement = document.createelement('a'); hiddenelement.href = 'data:application/pdf;' + encodeuri(data); hiddenelement.target = '_blank'; hiddenelement.download = 'myfile.pdf'; hiddenelement.click(); }).error(function(data, status, headers, config) { });
in spring:
fileinputstream in = new fileinputstream(new file(mygeneratedfile)); outputstream out = response.getoutputstream(); final int buffersize = 8192; byte[] buffer = new byte[buffersize]; int read; while ((read = in.read(buffer, 0, buffersize)) != -1) { out.write(buffer, 0, read); }
in javascript receive binary data of file pdf , save content in success section. when open file occurs problem format. issue function encodeuri? how can write correctly binary data? in advance
Comments
Post a Comment