title: How to display a server side generated PDF stream in javascript sent via HttpMessageResponse Content
body: <p>On my server side I am using ASP.NET MVC Web Api, where I am generating the PDF file with Crystal report and exporting it to PDF format. The code goes as follows:</p>
  
  <pre><code>[HttpPost]
  public HttpResponseMessage SetReport(string name, [FromBody]List&lt;KontoDto&gt; konta)
  {
              var response = Request.CreateResponse(HttpStatusCode.OK);
              var strReportName = "KontoReport.rpt";
              var rd = new ReportDocument();
              string strPath = HttpContext.Current.Server.MapPath("~/") + "Reports//" + strReportName;
              rd.Load(strPath);
              rd.SetDataSource(konta);
              var tip = ExportFormatType.PortableDocFormat;
              var pdf = rd.ExportToStream(tip);
             response.Headers.Clear();
              response.Content = new StreamContent(pdf);
              response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
              return response;
  
  }
  </code></pre>
  
  <p>My Javascript code is:</p>
  
  <pre><code>  $scope.xxprint = function () {
          console.log($scope.konta);
          $http.post('/api/konto/setReport/pdf', $scope.konta, { responseType: 'arraybuffer' })
              .success(function (data) {
                   var file = new Blob([data], { type: 'application/pdf' });
                  var fileURL = URL.createObjectURL(file);
                  window.open(fileURL);
              });
      };
  </code></pre>
  
  <p>This simply does not work. I don't know what's wrong with this code. I get the browser to open the pdf viewer, but it is empty. Also, the created pdf is correctly created as I can save it to disk and open it then with Adobe Acrobat viewer. The content of the HttpResponseMessage seems also correct viewed via Fiddler. See image:</p>
  
  <p><img src="https://i.stack.imgur.com/KduHl.png" alt="enter image description here"></p>