Save PDF and avoid the browser open

hello we have a windows server 2008 and we want the users download the PDF files when they click instead of open in the browser with acrobat reader. Is like a force to save and automatic downloading.
  If you have examples of code we use ASP, javascript preference. We don't use PHP.
Thank you
coerraceAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
Here's a little script I've used in the past to do just that:

<% 
    Response.ContentType = "application/octet-stream"
    FPath = server.mappath("pdf/portfolio.pdf") 
    Response.AddHeader "Content-Disposition","attachment; filename=" & FPath
    Set adoStream = CreateObject("ADODB.Stream") 
    adoStream.Open() 
    adoStream.Type = 1 
    adoStream.LoadFromFile(FPath) 
    Response.BinaryWrite adoStream.Read() 
    adoStream.Close 
    Set adoStream = Nothing 
    Response.End 
%>

Open in new window


I didn't write the script originally so credit goes to the link below:

http://www.sitepoint.com/forums/showthread.php?430610-How-to-force-pdf-download-not-open-in-browser-window
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
coerraceAuthor Commented:
Could yoy tell me how to use or call in an HTML or asp page. Want to know how to apply or how to ise this code.
Thank you
0
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
Do you already have the pdf files created? Maybe you can post your code that you use to lay your pdf files and I can help you modify it
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
You have to add some header info.   If you saw something in php, this is probably the similar solution in asp.   http:Q_21929242.html#a17166603
0
coerraceAuthor Commented:
Big Monty this is what I have in code is a file in .html:
<SCRIPT>
function download()
{
      
window.open('file2.asp');
}
</SCRIPT>
    <SPAN onmouseup='javascript:download()'; style='cursor:pointer;display:inline-block;white-space:nowrap;'><SPAN><TABLE onmouseover='this.className="buttonback1o"' onmouseout='this.className="buttonback1"'; class='buttonback1' cellspacing=0 cellpadding=0 height=100%;'><TH align=center valign=middle><SPAN style='white-space:nowrap;'><P class=buttontext>Download PDF</TH></TABLE></CENTER></SPAN></SPAN>

file2.asp is your code if you click mouse sends you to the page and display the content like text and not execute the VB code if I run the file.asp like http://xxx.xxx.xxx.xxx/file2.asp workks perfect download the file but we can't make http syntax we need to call in the same directory the .html it is we can't use http.
Thank you
0
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
As a starting point, put the code I posted in its own file (displayPdf.asp) , and on the page that lists out the files, have them link to that page, along with the path listed in the query string so it would look like

<a href ="displayPdf. asp? path=/PathToFile/filename.pdf">pdf name display</a>

Open in new window


Then on line 2, change it to

  FPath = server.mappath(Request. QueryString("path") ) 
  

Open in new window

0
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
Just saw your post, have a) at mine and see if it works for you. Let me know if you have any additional questions
0
coerraceAuthor Commented:
Worked perfect running the html from www http and your code in same dir.
Thank you
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.