title: Download pdf from restful service with spring using iText
body: <p>I have to downlaod a pdf file calling a rest api with spring. My code is the following:</p>
  
  <pre><code>@RequestMapping(value = "downloadPDF", method = RequestMethod.GET, produces = MediaType.APPLICATION_PDF_VALUE)
  public @ResponseBody ResponseEntity&lt;InputStreamResource&gt; getPDF() throws IOException {
  
      ByteArrayInputStream bis = GeneratePdfReport.createReport();
  
      HttpHeaders headers = new HttpHeaders();
      headers.add("Content-Disposition", "inline; filename=migration.pdf");
  
  
      return ResponseEntity
              .ok()
              .headers(headers)
              .contentType(MediaType.APPLICATION_PDF)
              .body(new InputStreamResource(bis));
  
  }
  </code></pre>
  
  <p>and this is the createReport method that prints a simple table into the document</p>
  
  <pre><code>public static ByteArrayInputStream createReport() {
  
  
      Document document = new Document();
      ByteArrayOutputStream out = new ByteArrayOutputStream();
  
      try {
  
          PdfPTable table = new PdfPTable(3);
          table.setWidthPercentage(60);
          table.setWidths(new int[]{1, 3, 3});
  
          Font headFont = FontFactory.getFont(FontFactory.HELVETICA_BOLD);
  
          PdfPCell hcell;
          hcell = new PdfPCell(new Phrase("Id", headFont));
          hcell.setHorizontalAlignment(Element.ALIGN_CENTER);
          table.addCell(hcell);
  
          hcell = new PdfPCell(new Phrase("Name", headFont));
          hcell.setHorizontalAlignment(Element.ALIGN_CENTER);
          table.addCell(hcell);
  
          hcell = new PdfPCell(new Phrase("Population", headFont));
          hcell.setHorizontalAlignment(Element.ALIGN_CENTER);
          table.addCell(hcell);
  
  
          PdfWriter.getInstance(document, out);
          document.open();
          document.add(table);
  
          document.close();
  
      } catch (DocumentException ex) {
  
          System.out.println("error");
      }
  
      return new ByteArrayInputStream(out.toByteArray());
  }
  </code></pre>
  
  <p>The problem occurs when I call the rest api and I get this error from the server</p>
  
  <pre><code>HTTP Status 406 – Not Acceptable
  
  The target resource does not have a current representation that would be acceptable to the user agent, according to the proactive negotiation header fields received in the request, and the server is unwilling to supply a default representation
  </code></pre>