Force download application pdf

There might come times when you click on a link to a file, for instance a PDF, and it opens in the browser but instead you want it to download.

If we take PDFs as an example, these will always open in the browser because that is how Adobe Reader is rigged to show the PDF, in the browser. To do otherwise we need to force the download.

Well there are solutions and i will outline them below.

HTML Download Tag

There is a new config option that you can use in a hyperlink

The code above does work but if you add this into a WYSIWYG it is slightly modified, and that new version also works so is probably a better version.

Notice that the download option now has parenthesis to hold a variable so it looks like a normal option. The rel="external" seems to be optional and could just be added by the JCE editor as a matter of course.

Variant

This could be the same command used better and also allows you change file names which is useful for dynamically create content.

This is a bit of a hack and is listed for completeness. It will cause a windows to open which will trigger the download and hopefully the new window will also dissapear.

PHP Headers

You can alter the Content-Type headers via your PHP session

application/force-download

By default all files are delivered using the content type application/force-download, which forces all browsers to display a “save file as” dialog instead of displaying the file.

.htaccess

This is a useful method because you can globally change download behaviour using the htaccess. The method is similiar to the PHP method where you change the headers sent to the browser but it is done on the server level.

Specify Files or File Types

 ForceType application/octet-stream Header set Content-Disposition attachment 

Global

AddType application/octet-stream .csv AddType application/octet-stream .xls AddType application/octet-stream .doc AddType application/octet-stream .avi AddType application/octet-stream .mpg AddType application/octet-stream .mov AddType application/octet-stream .pdf

These are other methods i have come across that might be useful to other people.

1. I found a very simple solution for firefox (only works with relative rather than direct href): add type="application/octet-stream"

2. Disable PDF plugins, this is more for the end user and is not applied on the server.

Tools> Add-ons> Adobe Acrobat(Adobe pdf plugin for Firefox)> DISABLE

Links