title: PDF file becomes invalid through REST API
body: <p>I have a very simple REST service written in Java:</p>
  <pre><code>@RequestMapping(path=&quot;/getPdf&quot;, method=RequestMethod.GET)
      public ResponseEntity&lt;byte[]&gt; getPdf() throws IOException {
      ClassLoader classloader = Thread.currentThread().getContextClassLoader();
      InputStream is = classloader.getResourceAsStream(&quot;sample/CleanCode.pdf&quot;);
              
      // At this point, the PDF file exists and weigths around 3.7Mb
      return new ResponseEntity&lt;byte[]&gt;(IOUtils.toByteArray(is), HttpStatus.OK);
  }
  </code></pre>
  <p>Which I call from Angular 10:</p>
  <pre><code>document.service.ts:
  
  getPdf(): Observable&lt;Uint8Array&gt; {
      // Fetches correctly
      return this.http.get&lt;Uint8Array&gt;(`${this.url.document}${this.getPdfUrl}`);
  }
  </code></pre>
  <p>To display in another tab, which should be very straightforward:</p>
  <pre><code>main.component.ts:
  
  this.documentService.getPdf().subscribe(pdfContent =&gt; {
      // 1st strange thing: pdfcontent.byteLength gives 5Mb instead of 3,7Mb
      const file = new Blob([pdfContent], { type: 'application/pdf' });
  
      const fileURL = URL.createObjectURL(file);
      window.open(fileURL);
  });
  </code></pre>
  <p>This opens a new tab with a temporary blob:</p>
  <pre><code>// For instance
  blob:http://localhost:4200/2aff6007-8f16-45d3-84a1-1bd0dff2eab9
  </code></pre>
  <p>And it does not work. It gives us a popup &quot;Failing to load PDF document&quot;. I tried a lot of things from various questions, without success (<a href="https://stackoverflow.com/questions/50260391/open-pdf-from-bytes-array-in-angular-5">here</a> or <a href="https://stackoverflow.com/questions/36721600/angularjs-byte-array-to-blob">here</a> for instance).</p>
  <p>Can anyone help me finding why my existing, valid PDF file becomes invalid / corrupted after passing through a REST call ? Does it have something to do with headers, or a missing configuration somewhere ?</p>
  <p>Thanks in advance;</p>