title: How to open PDF report (from report viewer) using ajax in asp.net mvc
body: <p>I want to print a PDF File from my application (rdlc report). So I need to display the file in the browser without downloading using Ajax. The following code is trying to open the file using <code>&lt;a&gt;</code>tag(<code>&lt;a href="~/.../" target="_blank"&gt;print &lt;/a&gt;</code>) but it does not work in the ajax call. Please provide a code sample or instruction in C#.</p>
  
  <p>Here is the generation of the PDF from the report viewer:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public void CreatePdfFromList(string fileName, string reportpath, ArrayList dsNameArray, ArrayList DTArray)
  {
      ReportViewer viewer = new ReportViewer();
      Warning[] warnings = null;
      string[] streamIds = null;
      string mimeType = string.Empty;
      string encoding = string.Empty;
      string extension = string.Empty;
      string filetype = string.Empty;
  
      viewer.SizeToReportContent = true;
      viewer.LocalReport.ReportPath = reportpath;
      viewer.ProcessingMode = ProcessingMode.Local;
  
      for (int i = 0; i &lt; dsNameArray.Count; i++)
      {
          ReportDataSource rds1 = new ReportDataSource((string)dsNameArray[i], (IEnumerable)DTArray[i]);
          viewer.LocalReport.DataSources.Add(rds1);
      }
  
      viewer.LocalReport.Refresh();
  
      byte[] pdfContent = viewer.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamIds, out warnings);
  
      Response.Buffer = true;
      Response.Clear();
      Response.ContentType = mimeType;
      //Response.AddHeader("content-disposition", "attachment; filename=" + fileName + "." + extension);
      Response.BinaryWrite(pdfContent);
      //Response.Flush(); // send it to the client to download
      Response.Cache.SetCacheability(HttpCacheability.NoCache);
      Response.End();
  }
  </code></pre>
  
  <p>and here is the ajax:</p>
  
  <pre><code>$.ajax({
          type: "GET",
          url: "/.../",
           data: {...},
           success: function (json) {
           //window.open(json);
           //open file i think...
           }
           })
  </code></pre>
  
  <p>When trying to show pdf content I use console.log(json). It shows me the string but the content appears like this:</p>
  
  <pre><code>�~�
  </code></pre>