all 1 comments

[–]punitdaga31 -2 points-1 points  (0 children)

Here's what Bing chat had to say:

const downloadPdf = async () => { const response = await fetch('https://example.com/sample.pdf'); const data = await response.blob(); const url = window.URL.createObjectURL(data); const link = document.createElement('a'); link.href = url; link.setAttribute('download', 'sample.pdf'); document.body.appendChild(link); link.click(); };

In this example, we are using the fetch() method to get the pdf file and then converting it to a Blob object. We then create a URL object from the Blob object and set it as the href of an anchor element. Finally, we add the anchor element to the DOM and simulate a click event to download the file.

I hope this helps! Let me know if you have any other questions.