Download PDF file using JAX-RS RESTful Webservice

Warning: mysqli_query(): (HY000/1030): Got error 28 from storage engine in /home/ehowtono/public_html/wp-includes/wp-db.php on line 2030

In this tutorial we are going to see about how to download pf file using JAX-RS RESTful web service @Produces(“application/pdf”) annotation.

Create maven web application project and add Jersey dependency in pom.xml. Find Jersey 2.x maven dependency configuration below. If you are new to maven refer our maven tutorials.

Jersey 2.x dependency in pom.xml

<project xmlns="" xmlns:xsi=""
  <name>RestTutorials Maven Webapp</name>
      <!-- JAX-RS -->
        <!-- Jersey 2.19 -->

package com.ehowtonow.webservice;



public class DownloadPDFFile {

 private static final String FILE_PATH = "C://ehowtonow//java-tutorials.pdf";
 public Response downloadFile() {
  File file = new File(FILE_PATH);
  ResponseBuilder responseBuilder = Response.ok((Object)file);
    "attachment; filename=\"java-tutorials.pdf\"");

@Produces(“application/pdf”) used to set output response is pdf file. Content-Disposition in response header to tell user agent to pop up download box to download file

Configure Jersey 2.x Servlet dispatcher

 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "" >

	<display-name>Restful Webservice Example</display-name>


Now you can run the service and access the service by calling the following URL


Ask your questions in eHowToNow Forum

Post your technical, non-technical doubts, questions in our site. Get answer as soon as possible, meanwhile you can help others by answering, unanswered questions.
To Ask new Question : Ask Question
Check our existing discussions : Questions & Answers

  1. Thirukural – Aalvinaiyutaimai – Kural 619
  2. Java – Executors Class
  3. TNPSC Librarian 2019 Library and Information Science Question with Answer PDF
  4. TNPSC Junior Inspector in Co-operative Department 2019 GENERAL Studies Question and Answer PDF
  5. Thirukural – Vinaiththitpam – Kural 664
  6. Thirukural – Kanvidhuppazhidhal – Kural 1177
  7. TNPSC Study Materials Geography Tamil 25
  8. Thirukural – Alararivuruththal – Kural 1146
  9. TNPSC Assistant Statistical Investigator 2015 Answer Key PDF
  10. TNPSC Assistant Director Of Industries And Commerce 2012 Commerce Question And Answer PDF
  11. Thirukural – Innaaseyyaamai – Kural 320
  12. Thirukural – Pasapparuparuvaral – Kural 1184
  13. விவசாயி கடைசி பக்க சேதியிலே – கவிதை
  14. Thirukural – Matiyinmai – Kural 601
  15. Thirukural – Sutrandhazhaal – Kural 530

Be the first to comment

Leave a Reply