How do you display .PDF in a browser?

SharukO

New Member
Hi,<BR><BR>I found this code in MSDN that is supposed to open Adobe Acrobat Reader and<BR>display a .PDF file in the browser. What it actually does for me is to display the contents of the file--eg %PDF ... (not in Acrobat).<BR><BR>How do I get the file to be opened with Acrobat? (I do have acrobat installed on the browser machine, and it does successfully display .PDF's from other web sites)<BR><BR><BR><%@ Page ContentType="application/pdf" %><BR><%@ Import Namespace="System.IO" %><BR><BR><BR>script language="vb" runat="server"><BR> Sub Page_Load(sender as Object, e as EventArgs)<BR> Const strFileName as String = "C: ransits.pdf"<BR><BR> ' Read the contents of a binary file<BR> Dim objStream as Stream = File.Open(strFileName, FileMode.Open)<BR><BR> Dim buffer(objStream.Length) as Byte<BR> objStream.Read(buffer, 0, objStream.Length)<BR> objStream.Close()<BR><BR> Response.BinaryWrite(buffer)<BR> End Sub<BR></script><BR>I did it using a codebehind page, but have this code...<BR><BR>Imports ADODB<BR><BR> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<BR> Dim stm As New Stream()<BR> Response.Clear()<BR> Response.ContentType = "application/pdf"<BR> Response.AppendHeader("Content-Disposition", "inline")<BR> stm.Open()<BR> stm.Type = StreamTypeEnum.adTypeBinary<BR> stm.LoadFromFile("c:file.pdf")<BR> Response.BinaryWrite(stm.Read)<BR> stm.Close()<BR> Response.Flush()<BR> Response.End()<BR> End Sub<BR><BR>now if you want to FORCE the file save prompt then do this change to the above code...<BR><BR>Response.ContentType = "octet/stream"<BR>Response.AppendHeader("Content-Disposition", "attachment; filename=file.pdf")<BR><BR>GL H5!Thanks! Just what I needed.<BR><BR>Best, Mark<BR><BR><BR>
 
Back
Top