How do I force the browser to download a pdf file instead of opening it in a tab?
Such a situation:
There is a simple landing page with a form, after filling in which a PDF file should be downloaded.
But instead, it opens in a browser window and it turns out that the user needs to take extra steps to download it.
serve with the header
Content-Type: application / octet-streamAnonymous
Now every first browser considers itself the best pdf viewer, so the server settings for forced download are easily ignored depending on the browser settings. Typically, the default settings are in favor of the browser.
It's easier not to fight this, but to ask the question: why should the user download the file? If anything, you can save it from the viewer.Anonymous
Content-Disposition: attachment; filename="filename.pdf"
The header must be given by the server.Ronan Hunt
Alternatively, attach a link with the download attribute to the form submit button.
<a href="ссылка на файл" download><button type="submit">Отправить форму</button></a>
To place the code, please use CodePen or similar tool. Thanks you!