Scott on Writing

Musings on technical writing...

Opening a PDF in a Popup Window In Internet Explorer

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

posted on Friday, February 02, 2007 6:17 PM

Feedback

# re: Opening a PDF in a Popup Window In Internet Explorer 2/4/2007 8:49 PM Elijah Manor

I'd really like to find a free tool to dynamically convert HTML to a PDF at runtime and allow a user to download that to his/her browser. Have you ran across such a tool?

# re: Opening a PDF in a Popup Window In Internet Explorer 2/6/2007 9:02 AM Bob Delamater

Why not use the report exporter component that Crystal Reports for .NET supplies? It will also auto export.

Bob

Title:  
Name:  
Url:
Protected by Clearscreen.SharpHIPEnter the code you see:
Comments   

Add To Your Reader

My Links

Archives

Post Categories

 

I am a Microsoft MVP for ASP.NET.
I am an ASPInsider.
<May 2008>
SMTWTFS
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567

Comment Stats

DayTotal% of Total
Sunday 1866.8%
Monday 37913.9%
Tuesday 45316.7%
Wednesday 50418.5%
Thursday 53519.7%
Friday 49418.2%
Saturday 1666.1%
Total 2717100.0%

Hour1Total% of Total
12:00 AM 652.4%
1:00 AM 682.5%
2:00 AM 622.3%
3:00 AM 742.7%
4:00 AM 572.1%
5:00 AM 1033.8%
6:00 AM 1084.0%
7:00 AM 1585.8%
8:00 AM 1716.3%
9:00 AM 1475.4%
10:00 AM 1716.3%
11:00 AM 1816.7%
12:00 PM 1886.9%
1:00 PM 1696.2%
2:00 PM 1605.9%
3:00 PM 1324.9%
4:00 PM 1073.9%
5:00 PM 923.4%
6:00 PM 913.3%
7:00 PM 963.5%
8:00 PM 833.1%
9:00 PM 782.9%
10:00 PM 792.9%
11:00 PM 772.8%
Total 2717100.0%

Comments by Blog Entry Date/Time

Day Entry MadeAvg.Total
Sunday 5.54144
Monday 5.22339
Tuesday 4.28419
Wednesday 7.67637
Thursday 6.90607
Friday 5.48411
Saturday 5.33160
Total 5.842717

Hour1 Entry MadeAvg.Total
12:00 AM 5.0035
1:00 AM 1.002
5:00 AM 0.000
7:00 AM 7.0035
8:00 AM 5.35107
9:00 AM 6.32278
10:00 AM 6.47246
11:00 AM 4.41181
12:00 PM 6.88330
1:00 PM 3.00111
2:00 PM 5.41222
3:00 PM 8.64285
4:00 PM 4.0589
5:00 PM 5.92154
6:00 PM 4.52113
7:00 PM 9.67174
8:00 PM 9.80147
9:00 PM 5.05111
10:00 PM 5.4265
11:00 PM 4.5732
Total 5.842717

Learn More About Comment Stats
1 - All times GMT -8...


Blog Stats

Favorite Web Sites

My Books

My MSDN Articles