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:
- Click on the link to view the report in the CrystalReportViewer in a popup window
- Click on the print icon
- Specify the pages to print. This refreshes the web page and shows it as a PDF
- 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.)