Solved

force downlod

Posted on 2002-06-14
17
228 Views
Last Modified: 2013-11-18
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
0
Comment
Question by:jgreaves
  • 5
  • 3
  • 2
  • +6
17 Comments
 
LVL 12

Accepted Solution

by:
lexxwern earned 100 total points
ID: 7078383
no. not possible.
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 7078386
rename it from filename.pdf to filename._pdf ...
then provide instructions for the users to remove the _ when saving the file.
0
 
LVL 12

Expert Comment

by:lexxwern
ID: 7078388
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
 
LVL 12

Expert Comment

by:lexxwern
ID: 7078390
knightEknight, isn't that very messy?
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 7078417
yes, but it would force the issue.  I like the right-click idea better, but it wouldn't force the download.
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 7078437
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
 
LVL 18

Expert Comment

by:bruno
ID: 7078507
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
 
LVL 11

Expert Comment

by:mouatts
ID: 7078713
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Expert Comment

by:desktop2
ID: 7080417
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
 
LVL 11

Expert Comment

by:mouatts
ID: 7080559
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
 

Expert Comment

by:endamcg
ID: 7092017
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
 
LVL 11

Expert Comment

by:mouatts
ID: 7092147
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
 
LVL 11

Expert Comment

by:mouatts
ID: 7093356
Thats a novelty the accepted answer is the wrong!
0
 

Author Comment

by:jgreaves
ID: 7093437
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
 

Expert Comment

by:sevenofnine
ID: 7176085
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
 
LVL 11

Expert Comment

by:mouatts
ID: 7176563
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
 

Expert Comment

by:sevenofnine
ID: 7178973
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

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction The Google Maps API offers various ways to draw dynamic and static maps.  Using a combination of PHP and JavaScript, you can draw active JavaScript maps that allow pan-and-zoom in the client browser window.  You can also draw "static" …
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now