Click to See Complete Forum and Search --> : Display a PDF in client browser


vsaravana
August 19th, 2003, 12:10 PM
I am trying to display a PDF file in a client browser and get garbled characters. Here is my code and please let me know if I am making any mistake. The client machine has Adobe ACrobat (Full version installed)

Thanks


<%
dim objFSO, objTS
FileName = "c:\1.pdf"
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objTS = objFSO.OpenTextFile(FileName)

NameFile=Right(FileName,Len(FileName)-InstrRev(FileName,"\"))

Response.ContentType = "application/pdf"

Response.Buffer = True
Do While Not objTS.AtEndOfStream
strChunk = objTS.Read(32)
strTmp = ""
For i = 1 to Len(strChunk)
strTmp = strTmp & ChrB(Asc(Mid(strChunk, i, 1)))
Next
Response.BinaryWrite strTmp
Response.Flush
Loop
objTS.Close
Set objTS = Nothing
Set objFSO = Nothing
%>

Satishpp
August 19th, 2003, 12:15 PM
Add this line after Response.ContentType = "application/pdf"


Response.AddHeader "Content-Disposition", "attachment; filename=filen.pdf"

hope this helps
Satish

vsaravana
August 19th, 2003, 04:23 PM
I tried adding the statement
Response.AddHeader "Content-Disposition", "attachment; filename=filen.pdf"

But now I get a dialog box which is asking wether I need to save, open (or) cancel. I would like to just read and display the PDF file in a webpage.


Saravana

khp
August 19th, 2003, 07:22 PM
If you are getting garbled output in the browser, the content type has probably not been properly set to application/pdf. But this is easy to check, select file->properties in IE or view->'page info' in netscape, and see what type the browser thinks the page is.

I suppose you might try changeing

Response.ContentType = "application/pdf"

to something like

Response.AddHeader "Content-Type=application/pdf"

But this is pure speculation on my part.

vsaravana
August 20th, 2003, 05:02 PM
The properties says
Type: Adobe Acrobat Document