aspose file tools*
The moose likes Servlets and the fly likes pdf in web browser Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "pdf in web browser" Watch "pdf in web browser" New topic
Author

pdf in web browser

rakhi sinha
Ranch Hand

Joined: Mar 26, 2012
Posts: 147
I have saved pdf in a file now i want to show that pdf in web browser .then how it is possible to that?
thanks in advance
Thakur Sachin Singh
Ranch Hand

Joined: Jun 15, 2010
Posts: 232

some pdf viewer software give plugin for browser to display pdf on any browser....try foxit pdf viewer or adobe


SCJP 6- 91%, IBM DB2, IBM RAD Certified
rakhi sinha
Ranch Hand

Joined: Mar 26, 2012
Posts: 147
Thakur Sachin Singh wrote:some pdf viewer software give plugin for browser to display pdf on any browser....try foxit pdf viewer or adobe



we cannot do it with the help of programming....
Thakur Sachin Singh
Ranch Hand

Joined: Jun 15, 2010
Posts: 232

yes you can do this but we can not write direct code for this, here you need to use third party api's, search on google for this.
Eshwin Sukhdeve
Ranch Hand

Joined: Mar 15, 2012
Posts: 80
http://viralpatel.net/blogs/2009/04/generate-pdf-file-in-java-using-itext-jar.html

check with this.
Anurag Verma
Ranch Hand

Joined: Mar 30, 2012
Posts: 124

if your question is something like you have a pdf on server & you want to display it on client machine's browser, then you have to do the following -

set response header Content-Disposition as inline
set response header Content-Type as application/pdf

After this, write your pdf file into the response.

you can use it directly or can use an iframe to display it within your web page. Hope that answers
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
If the client does not have software installed for viewing PDFs, then there's nothing the web app can do about that.

iText does not help with viewing PDFs; it is used to create and alter PDFs.
rakhi sinha
Ranch Hand

Joined: Mar 26, 2012
Posts: 147
Anurag Verma wrote:if your question is something like you have a pdf on server & you want to display it on client machine's browser, then you have to do the following -

set response header Content-Disposition as inline
set response header Content-Type as application/pdf

After this, write your pdf file into the response.

you can use it directly or can use an iframe to display it within your web page. Hope that answers

I have used this also but problem is not solved....
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
So what, exactly, is the code doing now, what, exactly, is the result of that, and how, exactly, does that differ from what you expected to happen?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16145
    
  21

The problem is more legal than technical.

Internet Explorer is forbidden from displaying PDF's in a browser window. It is likewise forbidden from allowing the viewing or editing of MS-Word or Excel documents or any similar applications.

Several years ago, a small company named Eolas sued Microsoft, claiming that they had a patent on that process. They won, and Microsoft was assessed a penalty of one half billion dollars. That's correct. As in "50 crore" dollars. Microsoft had no success in the appeal (although reportedly, they did get a reduction in how much to pay), so they pulled the functionality out of IE.

Eolas apparently had it in for Microsoft, since they announced that other vendors were allowed to continue to embed documents in their browers. I can and do view PDF's in Firefox.

More recently, Eolas reappeared in a lawsuit relating to their patents allegedly covering video streaming and other browser-interactive content. They lost that one, but not before collecting from a lot of big-name players.


Customer surveys are for companies who didn't pay proper attention to begin with.
Anurag Verma
Ranch Hand

Joined: Mar 30, 2012
Posts: 124

Please be precise on what you want , what is happening, provide exceptions/logs (& code if possible). In short, ask the correct & precisely detailed question.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16145
    
  21

Although a bare "It doesn't work" is something we discourage around here (we're weak in the ESP department), this is a common enough case that I'm pretty sure that it meant "It launched the Adobe Reader instead of opening in a browser" based on the original question.

Of course, I could be wrong. In which case we do need to know what actually happened.
Abhay Agarwal
Ranch Hand

Joined: Feb 29, 2008
Posts: 1162
    
    1

@ Tim - thanks for giving us nice information ....

~ abhay


Oracle Java Web Service Developer (1z0-897), Oracle certified Java 7 Programmer, SCJA 1.0, SCJP 5.0, SCWCD 5.0, Oracle SQL Fundamentals I
rakhi sinha
Ranch Hand

Joined: Mar 26, 2012
Posts: 147
rakhi sinha wrote:
Anurag Verma wrote:if your question is something like you have a pdf on server & you want to display it on client machine's browser, then you have to do the following -

set response header Content-Disposition as inline
set response header Content-Type as application/pdf

After this, write your pdf file into the response.

you can use it directly or can use an iframe to display it within your web page. Hope that answers

I have used this also but problem is not solved....


I am using following code but no pdf is displayed in the browser.a zero size pdf is generated because i think it is not taking signed pdf which is stored in resources folder but it is createing new signed pdf of zero size.I want that saved signed pdf( in resources folder) in my web browser..


how can i solve my problem..
rakhi sinha
Ranch Hand

Joined: Mar 26, 2012
Posts: 147
Bear Bibeault wrote:Please be sure to use code tags when posting code to the forums. Unformatted or unindented code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please click this link ⇒ UseCodeTags ⇐ for more information. Properly indented and formatted code greatly increases the probability that your question will get quicker, better answers.

I've gone ahead and added the code tags for you. See how much easier the code is to read?

thanks .i will take care of this in future.....
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16145
    
  21

You should NEVER attempt to write to your WAR. It isn't supported by the J2EE spec,it isn't guaranteed to work (getRealPath may return NULL), and you can lose important data when a new version of the WAR is deployed.

It is OK to READ signatures and model PDF files from within a WAR, but not to write or update. Officially, a WAR is a ZIP (JAR) format file, and you cannot open a member of a ZIP file for reading or writing the way you can do for an independent file. You cannot even reliably read the resource using getRealPath() for that reason, which is why there's a "getResourceAsStream()" method that handles that situation.

Always write to a location that's external both to the webapp (WAR) and to the webapp server.
rakhi sinha
Ranch Hand

Joined: Mar 26, 2012
Posts: 147
Tim Holloway wrote:You should NEVER attempt to write to your WAR. It isn't supported by the J2EE spec,it isn't guaranteed to work (getRealPath may return NULL), and you can lose important data when a new version of the WAR is deployed.

It is OK to READ signatures and model PDF files from within a WAR, but not to write or update. Officially, a WAR is a ZIP (JAR) format file, and you cannot open a member of a ZIP file for reading or writing the way you can do for an independent file. You cannot even reliably read the resource using getRealPath() for that reason, which is why there's a "getResourceAsStream()" method that handles that situation.

Always write to a location that's external both to the webapp (WAR) and to the webapp server.


thanks for your suggestion ......i have done it
 
Consider Paul's rocket mass heater.
 
subject: pdf in web browser