I'm getting some PDFs from the database through their URL and then I'm compressing them with JSZIP. Up there all right, so afterwards I use the FileSaver.js library and it allows me to keep it perfect but with a detail, from IE10 onwards, and I need to use it in IE8. Look for IE 8 does not work, there is an alternative where only save plain text files, on the other hand is Downloadify which is another library but only works partially in IE8 and only for files of up to 32kb. I found another call Blob.js and it is also not compatible.
I have seen the possibility of converting the zip between Base64, or uint8array etc etc to see if I can achieve something (since JSZip uses these compressions), but I have not achieved anything since IE8 is incompatible with the type of binary Blob, and all these conversions fall on Blob.
Has anyone managed to save a file from IE8 without being a plain text, and hopefully using JSZIP?
Thank you very much!
This is what I have that works in Crhome and IE10 onwards (compatible with the blob function)
var Promise = window.Promise;
if (!Promise) {
Promise = JSZip.external.Promise;
}
function urlToPromise(url) {
return new Promise(function(resolve, reject) {
JSZipUtils.getBinaryContent(url, function (err, data) {
if(err) {
reject(err);
} else {
resolve(data);
}
});
});
}
/////////////FUNCIONA EN CHROME///////////////////
function CreaZip(){
var zip = new JSZip();
var url = "/XXXXX/DownloadFile.do?TIP_Documento=X&TIP_Archivo=X&COD_Tribunal=X&CRR_IdDocumento=X&CRR_IdTramite=X";
/* var filename = url.replace(/.*\//g, ""); */
var filename = "test.pdf";
zip.file(filename, urlToPromise(url), {binary:true});
zip.generateAsync({type:"blob"})
.then(function callback(blob) {
// see FileSaver.js
saveAs(blob, "example.zip");
});
return false;
}