Print Page | Close Window

Download PDF file

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=2829
Printed Date: 29 March 2026 at 1:39pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Download PDF file
Posted By: Awangku
Subject: Download PDF file
Date Posted: 18 May 2003 at 9:31pm
Does anyone here know the script for force-downloading a PDF file other than right-clicking the link? I've tried a few but they don't seem to work. I've also read the help/explanation/tutorial/whatever on the topic but they only get me more confused. Any help here?



Replies:
Posted By: Bunce
Date Posted: 19 May 2003 at 1:41am

One way is to change the content-type and stream it to the user.

But in the end, its up to the user whether they want to download it or view it in their browser. Thats why we have the option of changing it ourselves.

I'd be a little pissed off if you tried to make my mind up for me!

Cheers,
Andrew



-------------
There have been many, many posts made throughout the world...
This was one of them.


Posted By: Awangku
Date Posted: 19 May 2003 at 2:16am

I totally agree with you, Bunce. In my case, though, I have to make the decisions for those people since the PDF files are quite huge (approximately 500KB). Opening them online is definitely not a good idea.

What I have in mind is when they click the link, the Save As dialog box would appear and they have the option to save it or open it online. I've tried a number of scripts but somehow they don't work.

Can you help?



Posted By: Bunce
Date Posted: 19 May 2003 at 3:05am

I assume you know your users then as 500KB is nothing to people on broadband.

Anyway, unless you show us your code we can't help. Try these links (which I found from google...its your friend!)

http://216.239.37.100/search?q=cache:rjeLVz7UF0cJ:www.experts-exchange.com/Developer/Web/Q_20523315.html+how+force+pdf+download&hl=en&ie=UTF-8 - http://216.239.37.100/search?q=cache:rjeLVz7UF0cJ:www.experts-exchange.com/Developer/Web/Q_20523315.html+how+force+pdf+download&hl=en&ie=UTF-8

http://www.4guysfromrolla.com/webtech/110100-1.shtml - http://www.4guysfromrolla.com/webtech/110100-1.shtml

http://www.faqts.com/knowledge_base/view.phtml/aid/4906 - http://www.faqts.com/knowledge_base/view.phtml/aid/4906

http://www.aspalliance.com/shark/articles/DnldFiles/DnldDoc.aspx - http://www.aspalliance.com/shark/articles/DnldFiles/DnldDoc.aspx



-------------
There have been many, many posts made throughout the world...
This was one of them.


Posted By: Mart
Date Posted: 19 May 2003 at 10:35am

pdf.asp:

<% response.ContentType ="application/pdf" %> 
<!--#include virtual="/myfile.pdf" -->



Posted By: karp13
Date Posted: 19 May 2003 at 2:13pm
Zip them


Posted By: Awangku
Date Posted: 19 May 2003 at 6:42pm
Originally posted by Mart Mart wrote:

pdf.asp:

<% response.ContentType ="application/pdf" %> 
<!--#include virtual="/myfile.pdf" -->

I suppose.. but how would you do it if you have 10 PDF files in one page? Would you use 10 include virtuals?



Posted By: Awangku
Date Posted: 19 May 2003 at 6:46pm

Originally posted by karp13 karp13 wrote:

Zip them

Yup.. a perfect solution.. but it would defeat the purpose. I did say I want to download a PDF file, didn't I? The problem with my users is they are of an older generation and not really as net-savvy as us. Even a step-by-step instruction would be too difficult for some of them. Believe me.. I know. To my everlasting frustation.



Posted By: Bunce
Date Posted: 19 May 2003 at 6:56pm

Have you even looked at the links I posted. All of them offer valid methods of doing what you want.

The method that Mart suggested is not the page that lists the PDF's to download - this is the page that one of those links point *TO*. It handles the process of streaming the PDF document to the user.

How about actually trying some of these methods and you might learn what is involved.

Then come back to us, post the code that you used and any error messages or problems you encountered. We can't help you otherwise.

 



-------------
There have been many, many posts made throughout the world...
This was one of them.


Posted By: Awangku
Date Posted: 19 May 2003 at 7:30pm

I'm trying them now. And I'll also look for others using our friend Google (I definitely have to use better search words).  I'll get back to you when I've found one that works.

Thanks Andrew.



Posted By: Awangku
Date Posted: 19 May 2003 at 11:54pm

Guess what? I've finally found it -- the script for downloading PDF files without any complicated coding. Although I'm not really sure whether it's 100% foolproof. What the heck! It works! All thanks to scooby who posted the script at the infinitemonkeys site.

Here's a copy of the script for you guys out there. Glad to share it with you.

<%@Language="VBScript"%>
<%
Option Explicit

Dim objStream
Dim strFilename

strFilename = Request.QueryString("FName")

Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Type = 1
objStream.Open
objStream.loadFromFile(Server.MapPath(strFilename))

Response.ContentType = "application/unknown"
Response.addHeader "content-disposition", "attachment;filename=" & Chr(34) & strFilename & Chr(34)
Response.BinaryWrite objStream.Read
objStream.Close
Set objStream = Nothing
%>

Andrew.. thanks heaps for your help. Really appreciate it.

 




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net