title: Dynamic PDF and opening a new window instead of downloading
body: <p>I have a web api that is returning a JSReport as an encoded byte array. No matter how i try and read the byte array I either get a black screen or an error message that says "failed to download pdf". If I create a hidden anchor tag and download the pdf it works fine. However, I do not want the user to download it, I would prefer they can view it right from their browser.</p>
  
  <p><strong>WEB API CALL</strong></p>
  
  <pre><code>   var data = LossReportService.GetLossSummary(request);
     var pdf_bytes = LossReportService.GeneratePDFUsingJSReport(data);
  
     byte[] myBinary = new byte[pdf_bytes.Length];
     pdf_bytes.Read(myBinary, 0, (int)pdf_bytes.Length);
     string base64EncodedPDF = System.Convert.ToBase64String(myBinary);
  
     var response = Request.CreateResponse(HttpStatusCode.OK, base64EncodedPDF);
     response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
     response.Content.Headers.ContentLength = pdf_bytes.Length;
  
     return response;                  
  </code></pre>
  
  <p><strong>Javascript</strong></p>
  
  <pre><code>$.ajax({
      type: "POST",
      url: "/Reporting/GetLossSummary",
      data: { dataObj },
  },
  success: function (data) {
     if (data != null) {
  
      //I have tried this
      var file = new Blob([data], { type: 'application/pdf;base64' });
      var fileURL = URL.createObjectURL(file);
      window.open(fileURL, "LossSummaryReport");
  
      //which gives me a "failed to load pdf document" error
  
      //and I have tried this, which just renders a blank page
      window.open("data:application/pdf," + encodeURI(data)); 
    }
  }
  });
  </code></pre>
  
  <p>Any suggestions would be greatly appreciated.</p>