Welcome to WebmasterWorld Guest from 50.19.156.19

Forum Moderators: ocean10000

Message Too Old, No Replies

Can't display pdf file

     

andrewsmd

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

WebmasterWorld Senior Member 5+ Year Member



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()

Ocean10000

2:47 am on Oct 30, 2011 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



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]

lucy24

3:24 am on Oct 30, 2011 (gmt 0)

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



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.

andrewsmd

1:59 pm on Nov 1, 2011 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



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?

lucy24

11:26 pm on Nov 1, 2011 (gmt 0)

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



The new server is sending a different MIME type so the browser doesn't know what to do.

andrewsmd

1:35 pm on Nov 2, 2011 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



So how do I fix that. I checked the MIME type and it has .pdf application/pdf. Any ideas?

lucy24

8:11 pm on Nov 2, 2011 (gmt 0)

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



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.

andrewsmd

9:17 pm on Nov 2, 2011 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



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.