wood burning stoves 2.0
The moose likes Servlets and the fly likes Open pdf in browser Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Open pdf in browser" Watch "Open pdf in browser" New topic

Open pdf in browser

R Sawant
Ranch Hand

Joined: Aug 08, 2005
Posts: 51
Hi all,
My servlet is sending pdf in the response. I want this pdf to open the pdf in the browser only, instead of opening in the Acrobat reader. Can i control this. Please help me out. Its urgent.


If you think you can, you can. If you think you can't, you are right.
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Ramdas Sawant
Welcome to JavaRanch!

In an effort to help you get the most from our forums, we've compiled a
list of tips for asking questions here. You can find the list in our
FAQ section here.
In particular, please see EaseUp to find out how adding the word "urgent" to your posts will usually slow down or stop responses.

Again, welcome to JavaRanch and good luck with your question.

As to your question:
Browsers can't display PDFs on their own. A PDF viewer (such as Acrobat) is needed. Some browsers can embed Acrobat as a plugin and will appear to display your PDF in the browser.
To do this, you need to add a Content-Dispostion header with the 'inline' keyword.
Search this and the JSP forum with keyword 'Content-Dispostion' for more information.
If you're only providing a link to the PDF (as opposed to streaming it with your own code) you may not be able to control what headers are sent.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ajay Krishnamurthy

Joined: Jul 28, 2006
Posts: 5
Hi Ramdas,
To display the PDF file in your browser you must have any one of the following things..
1) Your Desktop must have the (PDF reader like Acrobat)
other wise
2) Your Browser must have the plug in to display the .PDF files.

okie come to the point .. in your Servlet or JSP .. first you to set the content type as (MIME) txt/pdf and you to read tat stream as well as u have to write it in your page ..
You can get the source code from the "Google" Search.. If u cant get the code please feel free to ask me ..

Ajay Krishnamurthy
Praveen Babu
Ranch Hand

Joined: Jul 30, 2006
Posts: 138

You can also do two things :

1. Use the embed tag
2. Use the object tag

However these two will work only if acrobat plugin is installed.

Bye & Regards,

I agree. Here's the link: http://aspose.com/file-tools
subject: Open pdf in browser
It's not a secret anymore!