File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Services and the fly likes Return a file (pdf) through a web service Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Return a file (pdf) through a web service" Watch "Return a file (pdf) through a web service" New topic

Return a file (pdf) through a web service

Cory Max
Ranch Hand

Joined: Jul 20, 2005
Posts: 83
Hi Everyone,

I know this may seem like an odd request, but we would like our web service to return a pdf file... Is this possible? Could someone point me in the right direction?

Thanks again gurus.



There are only 10 types of people in this world... Those who understand binary and those who don't.
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 39547
The more common case is to transfer files from the client to the server, which is described in articles here and here. But the same techniques may be applicable to the reverse case as well.

Ping & DNS - updated with new look and Ping home screen widget
Ganesh Kolhe

Joined: Jul 05, 2009
Posts: 2
We have done with passing PDF byte array as String in String[] as return type where in we can pass other parameter from Web service
Please be at the blog
Lalit Bhatt
Ranch Hand

Joined: Dec 27, 2007
Posts: 69
check MTOM. There is support for same in JAX-WS. If you are in JAX-RPC than use SAAJ api's. It has capability to attach the attachments.

Java-JavaEE Hibernate Spring Spring Roo Web Applications
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 12675
We have done with passing PDF byte array as String in String[] as return type

Now THAT is a disaster waiting to happen since byte to String always involves character conversions.

Perhaps you wanted to talk about base64 encoding of a byte[] to a String?


Java Resources at
I agree. Here's the link:
subject: Return a file (pdf) through a web service
Similar Threads
WS and tomcat
sending pdf file to client as byte array
Save pdf from http inputstream to file
want to send pdf file to client from server. pdf is generated at server