CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Raymond Lewallen

Framework Design, Agile Coach, President Oklahoma City Developers Group, Microsoft MVP C#, TDD, Continuous Integration, Patterns and Practices, Domain Driven Design, Speaker, VB.Net, C# and Sql Server

Pdfs Hate Modal Dialog Windows

Well, after wasting much time and developing a nice headache, there seems to be no solution for getting a pdf to open in a modal dialog.

Now you would think something like this would work:

myWindow.caller = window.showModalDialog("/myReport.pdf")


but it doesn't work. All you get it a blank page. So lets try something else:

myWindow.caller = window.showModalDialog("/showReport.aspx")


and lets say we have the following in our System.Web.UI.Page.Load event handler:

Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/pdf"
Response.WriteFile(MapPath("myReport.pdf"))
Response.Flush()
Response.Close()


Ok, that doesn't do anything either. You still get a blank page. So after hours and hours of trying to make this work and looking at other peoples solutions, there is no solution. There is only a workaround. The work around is to create an IFrame on showReport.aspx, and the source of the IFrame would be the location of your pdf file. Viola! That works! But yeah, it sucks. Now you have to scroll the IFrame instead of the window itself, and printing becomes a worry. Not only that, but I need this to work with another third party software program that most likey won't work with an IFrame, and I don't even want to go through the troubles of seeing if thats going to work out alright. For those of you who don't know and use the product (sorry, can't tell you which one it is), you might think "We'll of course it will work. Its just an IFrame, anyways". We'll, the product, as awesome as it is, doesn't quite work like that.

So, in conclusion, what was my solution? window.open. Didn't want to do it this way, but maybe if I set the window size properties from screen.width and screen.height and take up the full screen, they'll be more inclined to close down the window rather than just minimize it out of the way.


Comments

Maz said:

you may wish to try <EMBED> tags in your code and try open the code seperatly. IE has some weird security issues with opening PDF straight, it prefers HTML
# December 15, 2004 12:36 AM

Raymond Lewallen said:

I wish I knew why opening a Pdf is so difficult, especially when there is a content type header value specificially for pdfs. I'll try both of your suggestions and see what I come with, thank you.
# December 15, 2004 1:56 AM

Pete said:

Just read this some years later...you no doubt fixed it some way or other but I've just stumbled across the same kind of problem and it looks like I've managed to fix it using <embed>.

This is using IE7 and Acrobat v8.0

So the same problem would seem to exist even 3 years down the line. Hurrah for computing. Don't you just love the way these really ANNOYING problems go ignored in all the official documentation you read...only when you actually want to do something useful and specific do these problems come out of the woodwork and you spend hours, days, weeks searching on the web to see if some poor soul has suffered before you. AAAGGGHH!

# May 31, 2007 10:28 AM

kalyan shah said:

How to make full screen in showModelDialog with no browser status bar

# July 16, 2007 6:16 AM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add

About Raymond Lewallen

Working primarily in the public sector during his career, Raymond has designed and built several high profile enterprise level applications for all levels of the government. Raymond now works as a solutions architect for EMC. Raymond is an agile coach, Microsoft MVP C# and also president of the Oklahoma City Developers Group and Oklahoma Agile Developers Group. Raymond spends a lot of his time learning and teaching such things as Test Driven Development, Domain Driven Design, Design Patterns and Extreme Programming practices and principles, to name a few. Raymond is also an advocate of Alt.Net. Raymond is primarily a framework guy, so don't ask him anything about UI :) Check out Devlicio.us!