function download(pdfUrl, fileName) { fetch(pdfUrl).then(resp => resp.arrayBuffer()).then(resp => { const file = new Blob([resp], {type: 'application/pdf'}); const fileURL = URL.createObjectURL(file); jQuery("#download-button-prev").attr('href', fileURL).attr('download', fileName); }); } download(linkUrl, docName);