I am trying to convert a blob object to a pdf and download it.
So far I've tried the following:
var downloadLink = document.createElement('a');
downloadLink.target = '_blank';
downloadLink.download = 'name_to_give_saved_file.pdf';
// convert downloaded data to a Blob
var blob = new Blob([file.$binary], { type: 'application/pdf' });
// create an object URL from the Blob
var URL = window.URL || window.webkitURL;
var downloadUrl = URL.createObjectURL(blob);
// set object URL as the anchor's href
downloadLink.href = downloadUrl;
// append the anchor to document body
document.body.append(downloadLink);
// fire a click event on the anchor
downloadLink.click();
The file size seems to be correct, but I cant view it since it seems to be damaged.
Viewing the PDF inside of my html file works like this:
$('#test').html('<embed width=100% height=100%'
+ ' type="application/pdf"'
+ ' src="data:application/pdf;base64,'
+ escape(file.$binary)
+ '"></embed>')
This works without any problems!
Now to my question... why is one working and the other one isn't?
Thanks for your help...