title: Convert byte array into blob (pdf file) and download using angular 5
body: <p>I'm receiving a byte array from server side and has converted it successfully to blob. However, when I'm trying to download it, it shows the file is corrupted. Below are my codes -</p>
  
  <pre><code>// In client side controller
  this.contractsService.downloadPdf(id)
        .then((result) =&gt; {
          var blob = new Blob([result], { type: "application/pdf" });
          var link = document.createElement('a');
          link.href = window.URL.createObjectURL(blob);
          link.download = "testing.pdf";
          link.click();
        });
  </code></pre>
  
  <p>And,</p>
  
  <pre><code>// In client side service
  private headers = new HttpHeaders({ 'Content-Type': 'application/json' });
  downloadPdf(id: number) {
      return this.http.get(this.apiRoutes.download + "/" + id, { headers: this.headers })
        .map((res: any) =&gt; res)
        .toPromise();
    }
  </code></pre>
  
  <p>Any sort of help will be very much appreciated.
  Thank you.</p>