Issue
I need to download the pdf file from the URL. I have tried the window.open(URL, ‘Download’) method but it does not download the file and it opens in the new browser tab.
downloadPDFFile() {
window.open('https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf', 'Download');
}
Solution
import * as fs from 'file-saver';
downloadFile(url) {
var filename = url.split('/').pop();
try {
fs.saveAs(url, filename);
}
catch (e) {
console.log(e)
}
}