Manojkumar P

Manojkumar P

  • NA
  • 25
  • 11.5k

How to print SSRS report automatically without print preview

Nov 4 2016 4:30 AM
How to print SSRS report automatically without print preview in browser. I'm using MVC4 application.
 
Here i will explain my scenario. In MVC application i have a (.cshtml) view passing parameter to report. This is my index.cshtml view.
 
Here is my webform page.(aspx)
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="printMvcApplication5.Reports.WebForm1" %>  
  2.   
  3. <%@ Register assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"   
  4. namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>  
  5.   
  6. >  
  7.   
  8. <html xmlns="http://www.w3.org/1999/xhtml">  
  9. <head id="Head1" runat="server">  
  10.     <title>title>  
  11.       
  12.     <script src="../Scripts/jquery-1.12.3.min.js" type="text/javascript">script>  
  13.       
  14.     <script src="../Scripts/jquery-migrate-1.2.1.min.js" type="text/javascript">script>  
  15.   
  16.      <script type="text/javascript" language="javascript">  
  17.          $(document).ready(function () {  
  18.              // Check if the current browser is IE (MSIE is not used since IE 11)  
  19.              var isIE = /MSIE/i.test(navigator.userAgent) || /rv:11.0/i.test(navigator.userAgent);  
  20.   
  21.              function printReport() {  
  22.   
  23.                  var reportViewerName = 'ReportViewer1'; //Name attribute of report viewer control.  
  24.                  var src_url = $find(reportViewerName)._getInternalViewer().ExportUrlBase + 'PDF';  
  25.   
  26.                  var contentDisposition = 'AlwaysInline'; //Content Disposition instructs the server to either return the PDF being requested as an attachment or a viewable report.  
  27.                  var src_new = src_url.replace(/(ContentDisposition=).*?(&)/, '$1' + contentDisposition + '$2');  
  28.   
  29.                  var iframe = $('<iframe>', {  
  30.                      src: src_new,  
  31.                      id: 'pdfDocument',  
  32.                      frameborder: 0,  
  33.                      scrolling: 'no'  
  34.                  }).hide().load(function () {  
  35.                      var PDF = document.getElementById('pdfDocument');  
  36.                      PDF.focus();  
  37.                      try {  
  38.                          PDF.contentWindow.print();  
  39.                      }  
  40.                      catch (ex) {  
  41.                          //If all else fails, we want to inform the user that it is impossible to directly print the document with the current browser.  
  42.                          //Instead, let's give them the option to export the pdf so that they can print it themselves with a 3rd party PDF reader application.  
  43.   
  44.                          if (confirm("ActiveX and PDF Native Print support is not supported in your browser. The system is unable to print your document directly. Would you like to download the PDF version instead? You may print the document by opening the PDF using your PDF reader application.")) {  
  45.                              window.open($find(reportViewerName)._getInternalViewer().ExportUrlBase + 'PDF');  
  46.                          }  
  47.                      }  
  48.   
  49.                  })  
  50.   
  51.                  //Bind the iframe we created to an invisible div.  
  52.                  $('.pdf').html(iframe);  
  53.   
  54.   
  55.              }  
  56.   
  57.              // 2. Add Print button for non-IE browsers  
  58.              if (!isIE) {  
  59.   
  60.                  $('#PrintButton').click(function (e) {  
  61.                      e.preventDefault();  
  62.                      printReport();  
  63.                  })  
  64.              }  
  65.              $('img').css('display','none');  
  66.          });   
  67.     script>  
  68.   
  69. head>  
  70. <body>  
  71. <div class="pdf">  
  72.     div>  
  73.     <form align="center" id="form1" runat="server">  
  74.     <div align="center">  
  75.     <input id="PrintButton" title="Print" style="width: 16px; height: 16px;" type="image" alt="Print" src="../../Reserved.ReportViewerWebControl.axd?OpType=Resource&Version=11.0.3442.2&Name=Microsoft.Reporting.WebForms.Icons.Print.gif" />  
  76.     div>  
  77.     <div align="center">  
  78.     <asp:ScriptManager ID="ScriptManager1" runat="server">  
  79.     asp:ScriptManager>  
  80.     div>  
  81.     <div align="center">  
  82.        <rsweb:ReportViewer ID="ReportViewer1" runat="server" DocumentMapWidth="100%" Height="100%"   
  83.         Width="100%" AsyncRendering="False" SizeToReportContent="True"   
  84.         WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt"   
  85.         WaitMessageFont-Underline="True">  
  86.     rsweb:ReportViewer>  
  87.     div>  
  88.     form>  
  89.    
  90. body>  
  91. html>  
Here is  (aspx.cs) page.
 
 
My problem is when i click preview button in (.cshtml) page it will open new window and display the report. In the report if click the print image it will ask for print preview in chrome and then if i click print in print preview it will print the report. What i need is when i click preview button in (.cshtml) page it should print the report directly. it should not take me to new window and display the report & do not ask for print preview in browser. please help to sort out this issue.

Answers (1)