title: Get a pdf (iText) through api REST using Spring MVC and AngularJS
body: <p>I have a interface in Java:</p>
  
  <pre><code>@RequestMapping(value = "/api/getPdf", method = RequestMethod.POST, headers = {"content-type=application/json"}
  @ResponseBody public ResponseEntity&lt;byte[]&gt; getPdf(@RequestBody final DatosPdf datosPdf);
  </code></pre>
  
  <p>Implementation:</p>
  
  <pre><code>public ResponseEntity&lt;byte[]&gt; getPdf(@RequestBody final DatosPdf datosPdf) {
      ByteArrayOutputStream archivo = new ByteArrayOutputStream();
      Document documento = new Document();
      PdfWriter.getInstance(documento, archivo);
      documento.open();
      documento.add(new Paragraph("Hello world"));
      documento.close();
      archivo.close();
  
      String filename = "hello.pdf";
      byte[] documentContent = archivo.toByteArray();
      HttpHeaders headers = new HttpHeaders();
      headers.setContentType(MediaType.parseMediaType("application/pdf"));
      headers.setContentDispositionFormData(filename, filename);
      headers.setCacheControl("must-revalidate, post-check=0, pre-check=0");
      ResponseEntity&lt;byte[]&gt; response = new ResponseEntity&lt;byte[]&gt;(documentContent, headers, HttpStatus.OK);
  
      return response;
  }
  </code></pre>
  
  <p>Function Javascript</p>
  
  <pre><code>HttpSrv.post('api/getPdf', datosPdf).then(function(pdf) {
  //CODE TO OPEN PDF FILE
  }, function(errorResponse){
  });
  </code></pre>
  
  <p>In the FRONT I receive the byte[]
  The Java implementation is correct?
  How I can open the pdf in the browser?</p>
  
  <p>Thanks!!</p>