Wolf Cat
Wolf Cat

Reputation: 171

Force download of PDF

I have the following link:

<a href="pdf/rental-application.pdf"><img src="images/button-download-rental-application.jpg" width="348" height="50" alt="Download Rental Application"></a>

However, sometimes it downloads the PDF and sometimes it opens it in the browser window.

I need it to always download.

I'm on a linux server using .html pages.

Thanks.

Upvotes: 0

Views: 119

Answers (2)

chasepeeler
chasepeeler

Reputation: 137

If you are using apache, try this in your config file (or a .htaccess)

<FilesMatch "\.pdf$">
  Header set Content-Disposition attachment
</FilesMatch>

The download attribute will work, but it's HTML5 specific, and I believe only works in firefox and chrome at the moment. If you do use the download attribute though, you should actually do it like this:

Upvotes: 1

Anhong
Anhong

Reputation: 232

This should work:

<a href="pdf/rental-application.pdf" download><img src="images/button-download-rental-application.jpg" width="348" height="50" alt="Download Rental Application"></a>

Just add a download in the tag.

Upvotes: 0

Related Questions