I am calling a rest api to my server and server is returning me path of stored pdf such as
API Reponse :
"http://xxx.xxx.xxx.xxx/files/mypdf.pdf"
Javascript Code
<script>
function download(filename) {
var element = document.createElement('a');
element.setAttribute('href', filename);
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
<button onClick="download('http://xxx.xxx.xx.xx/pdf/mypdf.pdf')>Click here to download pdf</button>
</script>
</p>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
When i am clicking on button new tab is opening and PDF is showing but i wants to directly download it on click on button.
How i can directly download PDF on browser from Rest Path. Please help me on this.