I need to create a hosted PDF file download when clicking the button without opening the browser how to do that it in Angular
Asked
Active
Viewed 860 times
1 Answers
1
If the PDF file is hosted at client side itself, just use HTML download
attribute on anchor element like below
<a href="/path/to/the/hosted/pdf/file.pdf" download>
Reference : download attribute

Sivakumar Tadisetti
- 4,865
- 7
- 34
- 56
-
Not in client-side, it has hosted in server-side – Aruna Wijethunga Nov 02 '20 at 06:04
-
Even it from the server-side, the above code works. What is the file link address you are getting and assigning to href attribute of anchor? and also your website address? – Sivakumar Tadisetti Nov 02 '20 at 06:09
-
If the file is being opened in new tab, then download attribute works like instead of navigating to new page, just downloads it – Sivakumar Tadisetti Nov 02 '20 at 06:09
-
Download yes, I tried this code but when I clicking the download button pdf file opening in a new tab..I need add when the user clicks button save that PDF file.. – Aruna Wijethunga Nov 02 '20 at 06:28
-
I think, that is because of cross origin sites issue. You can refer here for alternate solution https://stackoverflow.com/a/52466102/8593983 – Sivakumar Tadisetti Nov 02 '20 at 07:34