Created
April 17, 2019 13:12
-
-
Save lollotek/61e6276c014f55a744a13f7a5b499394 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Download multiple pdf. this force download instead open on browser | |
// Warning: with esternal url a CORS may occour | |
urls.forEach((url, i) => { | |
fetch(url) | |
.then(resp => { | |
resp.blob() | |
.then(blob => { | |
var downloadLink = document.createElement('a') | |
downloadLink.target = '_blank' | |
downloadLink.download = `document${i}.pdf` | |
var URL = window.URL || window.webkitURL | |
var downloadUrl = URL.createObjectURL(blob) | |
downloadLink.href = downloadUrl | |
document.body.appendChild(downloadLink) | |
downloadLink.click() | |
document.body.removeChild(downloadLink) | |
URL.revokeObjectURL(downloadUrl) | |
}) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment