In JAX-RS, for pdf file, annotate the method with @Produces("application/pdf") :

  1. Put @Produces(“application/pdf”) on service method.
  2. Set “Content-Disposition” in Response header to prompt a download box.

1. Download Pdf file in JAX-RS

Full example to download a pdf file from JAX-RS.

public class PdfService {
	private static final String FILE_PATH = "c:\\Android-Book.pdf";
	public Response getFile() {
		File file = new File(FILE_PATH);
		ResponseBuilder response = Response.ok((Object) file);
				"attachment; filename=new-android-book.pdf");

2. Demo

Access this URI pattern : “/pdf/get“.

Figure : Pdf file “c:\\Android-Book.pdf” from server is prompted for user to download, with a new file name “new-android-book.pdf

download pdf file from server

Download Source Code

Download it – (6 KB)


  1. JAX-RS @Produces JavaDoc
  2. List of the Application types
Tags :
Founder of, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.
My website is hosted by Liquid Web, I really like their fast and helpful support, it saved me a lot of time. Furthermore, their servers are extremely reliable, fast and stable, I don't remember when was the last time we had server downtime. Btw, they're offering $100 Coupon now, if you are sourcing for great hosting provider, go grab it.

Related Posts

Popular Posts