Opening a PDF in a Popup Window In Internet Explorer

Posted by: Scott on Writing, on 02 Feb 2007 | View original | Bookmarked: 0 time(s)

Today I was working on a web application where we have a number of Crystal Reports. To date, we were displaying them using the CrystalReportViewer Web control, but virtually all users, we found, were using the reports in the same manner:

  1. Click on the link to view the report in the CrystalReportViewer in a popup window
  2. Click on the print icon
  3. Specify the pages to print. This refreshes the web page and shows it as a PDF
  4. Click the print button on the PDF document in the browser

(Side note: Will there ever be a paperless office? Not in the health care industry, that's for sure!)

To streamline this process we decided to have the CR render as a PDF automatically. The code is pretty straightforward, and we ended up using code very similar to that presented in Use ASP.NET to Launch a Report as a PDF. Once this code was implemented, clicking a link would display a popup containing the report in PDF format... in FireFox.

In Internet Explorer 6, the popup window was empty. Using Fiddler, I could see that the PDF data was getting sent down, that the Content-Type MIME header was kosher, and so forth. A little Googling revealed that IE is a little fickle about displaying PDFs in popups. The workaround we ended up using - courtesy of Cowboy Bob's answer in the Unable to Display a PDF in IE When Within a Popup Window message post - was to trick IE by ending the URL with .pdf.

That is, in the window.open JavaScript call we previously had something like:

window.open('ShowCR.aspx?doc=1234', ...);

And to get this to work in IE we had to change this to:

window.open('ShowCR.aspx?doc=1234&iefix=fix.pdf', ...);

Basically, IE had to see .pdf at the end of the URL to display the PDF in the popup window. Bleh. Is this fixed in IE 7? I sure hope so.

(I also added a few lines of code to the Page_Load event handler in ShowCR.aspx so that if the querystring didn't end with fix.pdf, the page would Response.Redirect back to itself appending &iefix=fix.pdf to the URL. This way, if a previous or future link forgets or doesn't have the appropriate ending for this IE hack, it will automatically get tacked on and the report will properly display for our IE users, which is like 99% of the user base.)

Advertisement
Free Agile Project Management Tool from Telerik
TeamPulse Community Edition helps your team effectively capture requirements, manage project plans, assign and track work, and most importantly, be continually connected with each other.
Category: ASP.NET | Other Posts: View all posts by this blogger | Report as irrelevant | View bloggers stats | Views: 1182 | Hits: 85

Similar Posts

  • Common RadWindow issues and their solution more
  • The Lightbox Visual effect more
  • How to check your network connection state more
  • Flashback: Windows Forms Parking Window more
  • To leak, or not to leak(memory) - Part Two more
  • Vista: Glass more
  • Apple Safari for Windows and Microsoft Silverlight more
  • Accessing Html Document Content in other Frames more
  • Export Word to PDF docs compliant to PDF/A-1b via Aspose.Words more
  • Aspose.Pdf.Kit for .NET - 2.3.0.0 Released more

News Categories

.NET | Agile | Ajax | Architecture | ASP.NET | BizTalk | C# | Certification | Data | DataGrid | DataSet | Debugger | DotNetNuke | Events | GridView | IIS | Indigo | JavaScript | Mobile | Mono | Patterns and Practices | Performance | Podcast | Refactor | Regex | Security | Sharepoint | Silverlight | Smart Client Applications | Software | SQL | VB.NET | Visual Studio | W3 | WCF | WinFx | WPF | WSE | XAML | XLinq | XML | XSD