title: Download pdf from restful web services
body: <p>I am writing a rest service which will download the pdf when user access this service on users machine. below is the code of my controller class.</p>
  
  <p>When I tried to access below url in browser, it is downloading .JSON file and not PDF file.</p>
  
  <blockquote>
    <p>URL:- <a href="http://localhost:8080/test-service/downloadPDF?userId=abcd&amp;requestingLocation=6&amp;orderId=06006030" rel="nofollow noreferrer">http://localhost:8080/test-service/downloadPDF?userId=abcd&amp;requestingLocation=6&amp;orderId=06006030</a></p>
  </blockquote>
  
  <p>I have tried to use same code which was mentioned in below sites. It seems the straight forward code but not sure why it is not working.
  <a href="http://www.java2novice.com/restful-web-services/jax-rs-download-file/" rel="nofollow noreferrer">http://www.java2novice.com/restful-web-services/jax-rs-download-file/</a>
  <a href="https://www.javatpoint.com/jax-rs-file-download-example" rel="nofollow noreferrer">https://www.javatpoint.com/jax-rs-file-download-example</a></p>
  
  <p>Below is method in controller.</p>
  
  <pre><code>    @GET
      @RequestMapping(value = "/downloadPDF")
      @Produces("application/pdf")
      public @ResponseBody Response downloadDocument(@RequestParam("userId") String userId,@RequestParam("requestingLocation") String requestinglocation,@RequestParam("orderId") String orderId) {
              String path = "C:\\opt\\autobol\\logs\\autobol\\test2.pdf";
          File file = new File(path);  
              ResponseBuilder response = Response.ok((Object) file);  
              response.header("Content-Disposition","attachment; filename=\"javatpoint_pdf.pdf\"");  
              return response.build(); 
  
          }
  </code></pre>
  
  <p>It should download pdf file</p>
  
  <p>below is the content of downloaded file (file name downloadPDF.json):</p>
  
  <pre><code>{  
     "entity":"C:\\opt\\autobol\\logs\\autobol\\test2.pdf",
     "status":200,
     "metadata":{  
        "Content-Disposition":[  
           "attachment; filename=\"javatpoint_pdf.pdf\""
        ]
     },
     "annotations":null,
     "entityClass":"java.io.File",
     "genericType":null,
     "length":-1,
     "language":null,
     "location":null,
     "lastModified":null,
     "date":null,
     "closed":false,
     "cookies":{  
  
     },
     "statusInfo":"OK",
     "stringHeaders":{  
        "Content-Disposition":[  
           "attachment; filename=\"javatpoint_pdf.pdf\""
        ]
     },
     "links":[  
  
     ],
     "entityTag":null,
     "allowedMethods":[  
  
     ],
     "mediaType":null,
     "headers":{  
        "Content-Disposition":[  
           "attachment; filename=\"javatpoint_pdf.pdf\""
        ]
     }
  }
  </code></pre>
  
  <p>in downloadPDF.json file</p>