0
    <a
        href={`https://storage.yandexcloud.net/statrix-static/incomes.pdf`}
        download
    >
        Скачать описание к отчёту
    </a>

Above code i am using to download pdf from URL. But when i click it is opening the pdf url in browser instead of downloading.

Is there any to download pdf from link using React.js

1 Answers1

1
var link = document.createElement('a');
link.href = url;
link.download = 'file.pdf';
link.dispatchEvent(new MouseEvent('click'));
  • Please explain what this code does and how it does it. – M-Chen-3 Apr 21 '21 at 18:27
  • So you can use this code inside a function, add the click event handler to the a tag which will call this function. Give whatever name you want to give to the file. This should let you download the file for you. – Rushikesh Mhetre Apr 23 '21 at 07:43