I have this 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 I receive the binary data of file PDF and save the content in success section. When I open the file occurs a problem with the format. The issue is the function encodeURI? How can write correctly binary data? Thanks in advance