homepage Welcome to WebmasterWorld Guest from 54.205.207.53
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Microsoft / Microsoft IIS Web Server and ASP.NET
Forum Library, Charter, Moderators: ocean10000

Microsoft IIS Web Server and ASP.NET Forum

    
Can't display pdf file
andrewsmd

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 4380756 posted 5:12 pm on Oct 28, 2011 (gmt 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()

 

Ocean10000

WebmasterWorld Administrator 10+ Year Member



 
Msg#: 4380756 posted 2:47 am on Oct 30, 2011 (gmt 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]

lucy24

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



 
Msg#: 4380756 posted 3:24 am on Oct 30, 2011 (gmt 0)

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

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 4380756 posted 1:59 pm on Nov 1, 2011 (gmt 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?

lucy24

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



 
Msg#: 4380756 posted 11:26 pm on Nov 1, 2011 (gmt 0)

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

andrewsmd

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 4380756 posted 1:35 pm on Nov 2, 2011 (gmt 0)

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

lucy24

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



 
Msg#: 4380756 posted 8:11 pm on Nov 2, 2011 (gmt 0)

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

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 4380756 posted 9:17 pm on Nov 2, 2011 (gmt 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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Microsoft / Microsoft IIS Web Server and ASP.NET
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved