How to Force PDF File Auto Download

This Tutorial i will Focus How to Force PDF File Auto Download

Today i am working in a wordpress project and my client want, When someone click on the PDF File i will start Downloading. Searches many blocks and plugins but could not find that i wanted.
Always i prefer to use functions Because all Free plugins are not save for site. then i found a code at https://stackoverflow.com 

You put the following code in your .htaccess file:

<FilesMatch "\.(?i:pdf)$">
  ForceType application/octet-stream
  Header set Content-Disposition attachment
</FilesMatch>

But you should do it by FTP or Cpanel if you have enough knowledge, Check this out how to edit .htaccess

How to Force PDF File Auto Download
How to Force PDF File Auto Download

Right Click and click Edit, paste the below code after the <IfModule mod_rewrite.c>…</IfModule>

<FilesMatch "\.(?i:pdf)$">
  ForceType application/octet-stream
  Header set Content-Disposition attachment
</FilesMatch>

Save the file and done 🙂

I believe this way PDF File Auto Download will be start.

Note: Its better to add the above code via ftp or cpanel for save side.

Leave a Comment

Your email address will not be published. Required fields are marked *

0 Shares
Tweet
Share
Pin
Share