Welcome to WebmasterWorld Guest from 184.72.177.182

Forum Moderators: ocean10000

Message Too Old, No Replies

Can't display pdf file

     
5:12 pm on Oct 28, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:June 10, 2008
posts: 1130
votes: 0


I'm trying to actually display a pdf file on a web page. However, everything I've tried always prompts for a download. Does anyone have any idea how to do this? This is what I have been trying.

Dim MyFileStream = New FileStream(Server.MapPath("test.pdf"), FileMode.Open, FileAccess.Read)
Dim FileSize = MyFileStream.Length
Dim Buffer() As Byte
ReDim Preserve Buffer(CInt(FileSize - 1))
MyFileStream.Read(Buffer, 0, CInt(FileSize - 1))
MyFileStream.Close()
Response.BufferOutput = True
Response.ClearContent()
Response.ClearHeaders()
Response.AddHeader("Content-Length", Buffer.Length.ToString)
Response.AddHeader("content-disposition", "inline;filename=YourReport.pdf")
Response.ContentType = "application/pdf"
Response.BinaryWrite(Buffer)
Response.Flush()
Response.Clear()
2:47 am on Oct 30, 2011 (gmt 0)

Administrator

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month

joined:Jan 14, 2004
posts:852
votes: 0


What browser are you using?

Some browsers depending on the users settings will always ask to download and save the pdf.

Opening PDF files within Firefox [support.mozilla.com]
3:24 am on Oct 30, 2011 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

joined:Apr 9, 2011
posts:12720
votes: 244


Last time I looked, all browsers required a plug-in of some sort to view pdf files. You don't always notice it because the plug-in may come pre-installed with a name like "default plugin", but it isn't inherent in the browser. And sometimes what's built in may not work. (I had to add something to Safari because pdfs were showing up as black screens. A bit ironic, since in most respects Safari is better at making pdf files than any other browser.)

Are you trying to set the default behavior for your own browser, or for a file that others will be viewing? In general, trying to override unknown users' prefs is more trouble than it's worth.
1:59 pm on Nov 1, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:June 10, 2008
posts: 1130
votes: 0


I guess I have a question then. I know at one time, this pdf viewer was working. We moved to a new server, and now it's not working. Any thoughts there?
11:26 pm on Nov 1, 2011 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

joined:Apr 9, 2011
posts:12720
votes: 244


The new server is sending a different MIME type so the browser doesn't know what to do.
1:35 pm on Nov 2, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:June 10, 2008
posts: 1130
votes: 0


So how do I fix that. I checked the MIME type and it has .pdf application/pdf. Any ideas?
8:11 pm on Nov 2, 2011 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

joined:Apr 9, 2011
posts:12720
votes: 244


Drat. It was a shot in the dark. Always try the most obvious solution first. (Horses, not zebras.)

I assume the new server is not identical to the old server. That is, it's not just physically different. There are bound to be minor changes in the software even if overall it's on the same platform.
9:17 pm on Nov 2, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:June 10, 2008
posts: 1130
votes: 0


Yea, we went from Server 2003 IIS 6 SQL 2000 to Server 2008 R2 IIS 7. The problem is, this pdf isn't even showing in IE, it's breaking the page.