The first reason I preferred Nick's approach is because it allowed me to set it on a per folder basis so PDF's in one folder could still be opened in the browser while allowing others the ones we would like users to edit and then re-upload to be forced as downloads.
The second reason was because time is a consideration. Writing a PHP file handler to force the content disposition in the header will also take less time than an API, but still longer than Nick's approach. If you know how to turn on an Apache mod and edit the. It requires Linux hosting not Windows. This may not be appropriate approach for all uses as it requires high level server access to configure.
As such, if you have said access it's probably because you already know how to do those two things. If not, check Nick's blog for more instructions. As the html5 way my previous answer is not available in all browsers, heres another slightly hack way.
Now set location. This will cause the browser to download the file. Unfortunately you can't set file name or extension this way. Fiddling with the media-type could yield something. I needed to do this for files created with dynamic names in a particular folder and served by IIS. If you are using HTML5 and i guess now a days everyone uses that , there is an attribute called download. I've had some issues with the suggested solution that creates an a DOM element, and sets the download attribute.
It still displayed a popup warning in some browsers perhaps they got a little stricter by Adding the pdf mime type to the href attribute solved the browser popup warning, but it messed up the file the downloaded file got damaged and couldn't be opened. His code example uses an npm library though. Here's how to do it using js only:. The behaviour should depend on how the browser is set up to handle various MIME types. I recommend against this as it should be the users choice what will happen when they open a PDF file.
Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Asked 10 years, 4 months ago. First, let us see how to change the settings in Microsoft Edge to download PDF files instead of opening them. Step 3: In the Settings window, Choose Cookies and site permissions on the left-hand side, and within that choose PDF documents on the right-hand side.
This is a quick workaround that can be followed to download the pdf file in the Microsoft Edge browser. By default, Google Chrome opens a PDF file in the browser window instead of saving it to the downloads folder. To have PDF files open in the browser again, repeat these steps and select the Preview in Firefox option or Use other option to choose another program.
By default, Opera opens a PDF file in the browser window instead of saving it to the downloads folder. We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. Read More Do not sell my personal information. Close Privacy Overview This website uses cookies to improve your experience while you navigate through the website. Out of these cookies, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website.
We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies.
But opting out of some of these cookies may have an effect on your browsing experience. Necessary Necessary. Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
0コメント