0

Is there an easy way to create a download link for a pdf that is stored in src without having to create a servlet? The problem with a simple a href is it will try to open the link in adobe if it is installed. I would like a prompt to ask user to either save or open.

Thanks in advance!

Jason
  • 754
  • 3
  • 8
  • 22
  • 2
    That means adding/changing the response header of content type to `application/octet-stream` which isn't possibly directly on HTML (AFAIK). So it would be better to use a Servlet or another controller class to fire your file downloads. – Luiggi Mendoza Sep 04 '13 at 14:44
  • Tell your users to "Alt+Click on the link to download"? (This is Chrome-only, but still, give your users some credit when it comes to working with their browser unless you know they can't hack it.) – millimoose Sep 04 '13 at 15:47
  • 1
    Also, most browsers should support `Content-Disposition: attachment` which lets you keep the content type to whatever is appropriate for the file. – millimoose Sep 04 '13 at 16:07

1 Answers1

0

Considered there is no general solution as user Luiggi Mendoza pointed out you might still want to look at users T_D's commment under the following post to archive a solution that will be HTML 5 dependend:

How to make PDF file downloadable in HTML link?

Community
  • 1
  • 1
JBA
  • 2,769
  • 5
  • 24
  • 40
  • They're still using server side code to manipulate the response content type, the fact that PHP allows writing this code directly in your php page doesn't mean you escape from using server side components. – Luiggi Mendoza Sep 04 '13 at 14:55
  • You are absolutly right! I did a hell of a missthink there considered ROB W's answer! But wouldn't T_D's HTML 5 specific answer work? – JBA Sep 04 '13 at 15:06
  • Leave it there but update the content of your answer. Note that this can't be done without server side response manipulation. In Java, you can do this using a Servlet or a Filter. – Luiggi Mendoza Sep 04 '13 at 15:08
  • That might work if the client browser fully supports HTML 5, but the reality is that not all people uses chrome or firefox but IE 8 or even IE 7 – Luiggi Mendoza Sep 04 '13 at 15:08
  • Alright i edited the post and upvoted your comment since its defently the right answer that generally applies. – JBA Sep 04 '13 at 15:44