[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 326
  • Last Modified:

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
0
coerrace
Asked:
coerrace
  • 4
  • 3
1 Solution
 
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
 
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 new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
Scott Fell, EE MVEDeveloperCommented:
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

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now