GeeCON Prague 2014*
The moose likes JSP and the fly likes Error in opening pdf through jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "Error in opening pdf through jsp" Watch "Error in opening pdf through jsp" New topic
Author

Error in opening pdf through jsp

siddharth paul
Greenhorn

Joined: Apr 30, 2008
Posts: 20
In my application when a button is clicked in jsp to open a pdf file,
adobe reader returns the following error -
'There was an error opening the document. The file is damaged and could not be repaired.'


note:- Some time the pdf luckly goes open at 3/10 attempts ratio.

Is this a bug in adobe or any point our application is missing?
Whether this can be a result of load on server?

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61299
    
  66

Use a servlet not a JSP. JSPs are meant to server text resources not binary.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61299
    
  66

Please read this article for why.
siddharth paul
Greenhorn

Joined: Apr 30, 2008
Posts: 20
Thanks for the wonderfull article.

I read the part
"Why does everyone tell me to use a servlet to send binary data to the browser? I wanna use a JSP!"


The problem is i can't change the application model because of insufficiant access only can fix the bugs.
Can we sure it's because application is sending binary data to the browser in a jsp?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61299
    
  66

siddharth paul wrote:Can we sure it's because application is sending binary data to the browser in a jsp?

PDFs are binary, so yes.
ujjwal soni
Ranch Hand

Joined: Mar 28, 2007
Posts: 403
Hi,

Go through below links.

Library for generating pdf's in java

http://www.lowagie.com/iText/

An example of using iText to generate a PDF file can be found at http://www.avajava.com/tutorials/lessons/how-do-i-write-to-a-pdf-file-using-itext.html.

An example of serving up a PDF file from a servlet can be found at http://www.avajava.com/tutorials/lessons/how-do-i-serve-up-a-pdf-from-a-servlet.html.


Cheers!!!

Ujjwal B Soni

<baroda>
<gujarat>
<india>
<919998971048>


Cheers!!!
Ujjwal B Soni <baroda, gujarat, india> <+919909981973>
"Helping hands are better than praying lips......"
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61299
    
  66

ujjwal soni wrote:Library for generating pdf's in java

He's not generating PDFs -- just serving existing ones.

The issue is the inappropriate use of JSP to server binary data.
siddharth paul
Greenhorn

Joined: Apr 30, 2008
Posts: 20
Thanks to you all for your wonderfull suggestion.
 
GeeCON Prague 2014
 
subject: Error in opening pdf through jsp