Reputation: 2997
I'm currently using the jszip, jszip-utils, and FileSaver
to zip and download several PDFs.
self.createZip = function () {
var docs = self.list.filteredItems();
var zip = new JSZip();
var count = 0;
var zipFilename = "zipFilename.zip";
docs.forEach(function (item) {
var filename = item.formDesc() + "_" + item.id() + ".pdf";
// loading a file and add it in a zip file
JSZipUtils.getBinaryContent('../career/document/StreamFile/?path=' + item.fileName(), function (err, data) {
if (err) {
throw err; // or handle the error
}
zip.file(filename, data, { binary: true });
count++;
if (count == docs.length) {
zip.generateAsync({ type: 'blob' }).then(function (content) {
try {
saveAs(content, zipFilename);
} catch (e) {
console.log(e);
}
});
}
});
});
This function currently works on all latest browsers except IE11. In IE11 is gets all the files, but Hangs on saveAs.
Upvotes: 1
Views: 1323
Reputation: 946
Try the following after your SaveAs statement to clear the buffer
content = null;
Upvotes: 2