Need a new web host or having a problem with a script? Tips and advice on the best way to design, build and maintain your most valuable asset - your website!

How to force a download of pdf?

435pjjau251
Posts: 44
Joined: 17 Jun 11
Trust:

How to force a download of pdf?

Not sure if this is in the right section, as I don't know how to begin doing it!

I have several pdfs on my site which I sell using Paypal. I am currently emailing them out on payment, but it's not a very efficient system, so I'm going to use the redirect feature on Paypal to send the buyer to a page with a link to the pdf.

I then want to have a button or link for the buyer to click to download the pdf to their own computer, rather than have the pdf opening up in the browser.

I guess html won't do this? PHP? Javascript? Anybody got a simple script/link where I can copy and paste some simple code?
  • 0
essexboyracer
Posts: 105
Joined: 02 May 11
Trust:
I think a lot of this is down to browser preferences, how to handle mime types. I would give simple directions such as , "right mouse button and save target as". If you're really bothered try dynamicdrive.com or http://www.google.com/search?q=jquery+f ... f+download
  • 0
PremiumMember
jmpruitt
Posts: 3918
Joined: 19 Jun 09
Trust:
I always save mine into a compressed zip file. then they just download the zip file and extract the pdf doccument.
  • 0
Do you want to use your online content to Educate others, inspire them to action, and run a profitable business for yourself and your family? I can help you get started
https://www.youtube.com/channel/UCUvDlGM242pI2D5TUOCWd7A
 
thel.online.ph
Posts: 102
Joined: 13 Sep 11
Trust:
Hi,

As I research in internet to find some suitable solution, I found these finest tricks on how to force a download a pdf. – by adding the following code into your httaccess file.

FilesMatch "\.(pdf|PDF)"
ForceType application/pdf
Header set Content-Disposition attachment
</FilesMatch>

The code will match perfectly for both lower case and upper case PDF extension by using regular expression and OR operator in the following line.

<FilesMatch "\.(pdf|PDF)">

And thats it… You have now the control in Forcing PDF to download.

Hope that helps
  • 0

This topic was started on Aug 05, 2011 and has been closed due to inactivity. If you want to discuss this topic further, please create a new forum topic.