title: Printing Crystal Reports from a Crystal Reports Viewer (ActiveX, ASP.Net)
body: <p>I'm having some serious issues trying to get a Crystal Reports report printed from an ASP.Net page.  Here is the current setup:</p>
  
  <ul>
  <li>A Crystal Reports viewer is set up on a page.  The report appears fine when viewing the report.</li>
  <li>The report viewer PrintMode is set to ActiveX</li>
  <li>I am setting the report data source from a session variable, as per SAP's recommendation (found in one of their knowledge base articles).  The report data source is being set by a call to a WCF service.  The data being passed into the report is fine.  (Again, the report displays just fine, showing all content like it should).</li>
  <li>The build target for the ASP.Net application and related services are x86.</li>
  <li>Everything is using Crystal Reports version 13, and the ASP.Net web application is using .Net 4.  It is being viewed in Internet Explorer 8.</li>
  <li>I've tried checking the ActiveX settings on Internet Explorer 8, and none of them should be a problem (everything is either set to allow or prompt).</li>
  <li>The error happens regardless of running it from the IDE or from a set up website on a separate server.</li>
  <li>The settings for the application pool in IIS on the other server are set to allow 32 bit applications.</li>
  </ul>
  
  <p>When I click on the Print icon on the report viewer, I get the following error message:</p>
  
  <p>"An communication error occurred.  Printing will be stopped."</p>
  
  <p>This same error happens more than one machine.  If I click OK on the error message the dialog underneath says "Please wait while the Crystal Reports Print Control is loaded.".  If I wait, nothing happens.  There is no prompt to install an ActiveX control, and nothing pops up allowing me to select a printer (of which I know several are installed).</p>
  
  <p>I've tried doing the following things, none of which have worked:</p>
  
  <ul>
  <li>Switch the report type to PDF.  If I do this, and click the print button on the report viewer I get the following error:</li>
  </ul>
  
  <p>Microsoft JScript runtime error: Object required."</p>
  
  <p>It breaks on this line in particular:</p>
  
  <p>bobj.crv.stateManager.setComponentState('MainContent_reportViewer_<em>UI',eval('('+document.getElementById('</em>_CRYSTALSTATEctl00$MainContent$reportViewer').value+')'));</p>
  
  <p>There are several dynamic images in the report, but all of them are being displayed correctly when viewing the report.  They are the only binary objects that I can think of that would be associated with this report.  The error is happening in the dynamically created code for the page - not something that I have written.</p>
  
  <ul>
  <li>I've tried manually installing the ActiveX control from the correct .cab file.  This made no difference in any of the scenarios.</li>
  <li>I've installed the latest Crystal Reports service pack (service pack 3).  Again, this didn't change anything.</li>
  <li>I've tried setting up a Virtual Directory for the CrystalReportViewers13 inside the Default Web Site, as recommended by some forum posts I came across.  This also has had no effect.</li>
  <li>Enabling ViewState on the page has no effect on whether printing works or not.</li>
  <li>I've tried adding my own print button and a drop down list with a list of available printers.  When I click my own custom print button and call PrintToPrinter(), I get the same error message as trying to print a PDF report:</li>
  </ul>
  
  <p>"Microsoft JScript runtime error: Object required" </p>
  
  <p>...and it breaks on the same line as when trying to print a PDF report when clicking the Print button.</p>
  
  <p>I've been beating my head against this for at least a day now, and I'm fresh out of ideas.  Anyone have any idea what might be causing this?</p>
  
  <p>EDIT:</p>
  
  <p>Well, here's what I did in order to get things to work.  It ended up being a lot simpler of a fix than what I was thinking:</p>
  
  <ul>
  <li><p>Stuff the entire ReportDocument into the session.  Your page load should look something like this:</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
  {
      if (Session["report"] != null)
      {
          reportViewer.ReportSource = Session["report"];
      }
  
      BuildReport();
  }
  </code></pre></li>
  <li><p>Keep the ReportViewer as simple as possible - don't specify the report type (PDF or ActiveX).  Setting it to anything seemed to result in problems.  This is what it looks like in the page source:</p>
  
  <p></p></li>
  </ul>
  
  <p>... and that was it.  I can't believe I spent about a day trying to get it to work when it ended up being so simple.  Hopefully this post helps anyone else facing the same problem.</p>