Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why not PDF shows in browser eventhough I have Acrobat Reader?

Status
Not open for further replies.

geminihk

Programmer
Nov 11, 2002
21
0
0
HK
Hi All,

I have an asp program to show my PDF file in the browser. I have installed fulle Adobe Acrobat S/W including the reader.

But my browser showes unidentified characters in the browser with the following program which i saw from the internet. Please help me to sort it out.

Also I have tried the famous DownloadManager program in which my PDF files are forcing the dialogue to open the document.

Basically I want to view the PDF contents in the browser if acrobat reader is installed in the machine.

strFile=fileName "Here is my PDF file name
Dim FOLDER_PATH: FOLDER_PATH=Server.MapPath("\pdffolder")
If Right(FOLDER_PATH, 1)<>"\" Then FOLDER_PATH=FOLDER_PATH&"\"
strFile=FOLDER_PATH & strFile

' get full path of specified file
'strFilename = server.MapPath(strFile)
strFilename=strFile


' clear the buffer
Response.Buffer = True
Response.Clear

' create stream
Set s = Server.CreateObject("ADODB.Stream")
s.Open

' Set as binary
s.Type = 1

' load in the file
on error resume next


' check the file exists
Set fso = Server.CreateObject("Scripting.FileSystemObject")
if not fso.FileExists(strFilename) then
Response.Write("<h1>Error:</h1>" & strFilename & " does not exist<p>")
Response.End
end if


' get length of file
Set f = fso.GetFile(strFilename)
intFilelength = f.size


s.LoadFromFile(strFilename)
if err then
Response.Write("<h1>Error: </h1>" & err.Description & "<p>")
Response.End
end if

' send the headers to the users browser
Response.AddHeader "Content-Disposition", "attachment; filename=" & f.name
Response.AddHeader "Content-Length", intFilelength
Response.CharSet = "UTF-8"
Response.ContentType = "application/PDF"

' output the file to the browser
Response.BinaryWrite s.Read
Response.Flush


' tidy up
s.Close
Set s = Nothing


thanks in advance for your time.
 
Does it open as you wish if you just make a normal hyperlink to the file?
 
Thank you Sheco for your reply.

Even hyperlink not opens my PDF in Browser rather opens thru acrobat. In my Acrobat's preferences my "Display in Browser" check box is cleared. is it b'cos of that?.

Well, I need my program opens the PDF in browser without considering the client side set up. Is it possible?

Thanks once again.
 
Thanks emoxley...upgrading the reader to the latest verision shows properly. But I can not expect all my clients are using the latest version. I thought may thru asp program ContentType I can set the view option either in-line or attachment.

Thanks to pgorule as well.
 
Since the hyperlink behaves the same way as your ASP it seems quite likely that this behavior is determined by client-side configurations instead of by server-side settings. If it is a browser/windows issue then there may not be any ASP solution.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top