homepage Welcome to WebmasterWorld Guest from 54.227.12.219
register, free tools, login, search, subscribe, 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




msg:4380758
 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




msg:4381261
 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




msg:4381269
 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




msg:4382071
 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




msg:4382341
 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




msg:4382544
 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




msg:4382777
 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




msg:4382806
 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