force downlod

I have a link to a pdf on my web page.  Since I have the acrobat plugin it opens the pdf in the browser window.  But what I'd like it to do is force the use to download the pdf rather than opening it since it large. Is there a way to force the download
jgreavesAsked:
Who is Participating?
 
lexxwernConnect With a Mentor Commented:
no. not possible.
0
 
knightEknightCommented:
rename it from filename.pdf to filename._pdf ...
then provide instructions for the users to remove the _ when saving the file.
0
 
lexxwernCommented:
if a a browser understands then it will always try to open/. but you can leave a message saying try to save the file by right clicking and choosing "save file as"
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
lexxwernCommented:
knightEknight, isn't that very messy?
0
 
knightEknightCommented:
yes, but it would force the issue.  I like the right-click idea better, but it wouldn't force the download.
0
 
COBOLdinosaurCommented:
I think I saw something like this in a similar question. If you are on a Microsoft server, you can probably set up your link as an ASP page and feed the pdf down from the server with a response.header that indicates the file should be downloaded.

<%
Response.ContentType = "any/any"
Response.AddHeader "Content-disposition", "attachment; filename=myfile.pdf"
%>

my ASPskills are pretty limited, so this is just a shot in the dark.

Cd&
0
 
brunoCommented:
Cd&,

I think i remember the Q you are thinking of, and what it was doing was actually reading in the file using FSO, and then writing it back out....also a messy solution.

Another messy solution would be to remove the PDF MIME types from the server, the server won't recognize what type of file it is, and will only give a "save as" dialog box.



BRUNO
0
 
mouattsCommented:
CD you are basically correct although you can do this on any server in the approriate language with one exception and that is ASP. It has no way of opening a binary file (such as a PDF) as a binary file, it can only open it as a text file and hence corrupts it in the process.

Actually the proper mime type to us is application/octet-stream.

IE has a nasty habit when you send it an unknown mime type such as "any/any" of looking at the extension (which it will see as pdf) and then assumes application/pdf as the mime type.

For this same reason removing the mime-type pdfs will only work if the default mime type for unknown file types is application/octet-stream. Often however it is text/text so the client will attempt to open it as a text file which of course is both wrong and not what we want to achieve.

And of course even if the server is set correct all PDFs server will now become downloadable only.

HTH
Steve
0
 
desktop2Commented:
Over-ride the mime-types to turn .pdf files into another
mime-type


Add string      application/octet-stream pdf zip exe
into a .htaccess file in the directory you want the change.
0
 
mouattsCommented:
desktop2 we've basically just said that except that doing you way all pdfs will be downloaded  which is not neccesarily what is wanted.
0
 
endamcgCommented:
Best to keep it very simple. Why not just stick it into a zip file and save any messing.

As a follow up Q, does changing the http:// to ftp:// make any difference??



0
 
mouattsCommented:
Sending it as octet-stream amounts to the same thing except that the filename passed is correct whereas passing it as a zip is not.

Passing it as ftp doesn't help as IE will only open the saveas dialog for those file types that it doesn't understand.

Steve
0
 
mouattsCommented:
Thats a novelty the accepted answer is the wrong!
0
 
jgreavesAuthor Commented:
From: mouatts
CD you are basically correct although you can do this on any server in the approriate language with
one exception and that is ASP. It has no way of opening a binary file (such as a PDF) as a binary file,
it can only open it as a text file and hence corrupts it in the process.

I'm using ASP so so far according to the threads so far it can't be done
0
 
sevenofnineCommented:
I've done this using ASP and the MDAC components, as follows:

<%
Response.Buffer = True
Dim strFilePath, strFileSize, strFileName

Const adTypeBinary = 1
strFileSize = Request.QueryString("Size")

Response.Clear

'*******************************
' Requires MDAC 2.5 to be stable
' I recommend MDAC 2.6 or 2.7
'*******************************
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = adTypeBinary
FileName = Right("00000" & Request("ArticleID"),5)
objStream.LoadFromFile "C:\Inetpub\wwwroot\kb\" & Request("ARTICLEID") & ".pdf"
ContentType = "application/octet-stream"

Response.AddHeader "Content-Disposition", "attachment; filename=NS" & FileName & ".pdf"
Response.AddHeader "Content-Length", strFileSize
' In a Perfect World, Your Client would also have UTF-8 as the default
' In Their Browser
Response.Charset = "UTF-8"
Response.ContentType = ContentType
Response.BinaryWrite objStream.Read
Response.Flush

objStream.Close
Set objStream = Nothing %>
0
 
mouattsCommented:
sevenofnine.

Yep what you are doing is basically ok, however as I suggested before you can set your webserver up to do this without the need to do all this processing.

Steve
0
 
sevenofnineCommented:
Steve,

The reason I am doing it this way is because on our server we like to both link to the PDF's in a "View now" kind of way, and in a "Here, download this file" kind of way.

The processing time/overhead is not a huge issue.

Cheers,
seven
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.