Ok, Let's say I have document data stored somewhere, let's arbitrarily take this pdf.
Issue #1. What I want to do is make an AJAX call to this URL (because I need to pass some authentication headers and it is cross domain). Then take the returned data, create a blob url for it, append an iFrame to the DOM, and direct the src
to the blob url.
Currently my code looks like this:
$.ajax({
url:'http://www.grida.no/climate/ipcc_tar/wg1/pdf/tar-01.pdf'
}).done(function(data){
var file = new Blob([data], {type:'application/pdf'}),
url = URL.createObjectURL(file),
_iFrame = document.createElement('iframe');
_iFrame.setAttribute('src', url);
_iFrame.setAttribute('style', 'visibility:hidden;');
$('#someDiv').append(_iFrame);
});
Unfortunately, I am getting a 'Failed to Render PDF' in the iFrame.
Issue #2. I'd like this to result in a file download prompt. Not sure how to guarantee this given that PDF's will naturally just display in the iFrame.
%PDF-1.5 %���� 2504 0 obj <</Linearized 1/L 3722399/O 2506/E 388168/N 36/T 3720768/H [ 462 773]>> endobj 2511 0 obj <</DecodeParms<</Columns 3/Predictor 12>>/Filter/FlateDecode/ID[<F9EFEA8C46FA46DBA17E65AF85B66228><EF984B2A947E994D999C77E6D2021030>]/Index[2504 10]/Info 2503 0 R/Length 47/Prev 3720769/Root 2505 0 R/Size 2514/Type/XRef/W[1 2 0]>>stream h�bbd
b9�����]�x?abP|...
– Schneider