Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

open a pdf file from a servlet  RSS feed

 
sathish kannan
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI guys ,
When i am trying to open a PDF through a servlet it is poping with an acrobat error with the message
" The file is damaged and couldnot bt opened"

I am using the following code to display the pdf file from the serlvet,
File reportFile = new File(pdfFilename);
OutputStream ost = res.getOutputStream();
res.setHeader("Content-Disposition", "inline;filename="+pdfFilename+"\"");
res.setContentType("application/pdf");
BufferedInputStream buffIn = new BufferedInputStream(new FileInputStream(reportFile));
int iBuf;
while ((iBuf=buffIn.read())!=-1)
ost.write((byte) iBuf);
ost.flush();
buffIn.close();
ost.close();
If any problem in the code please let me know.
 
Hari babu
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Which browser are u using to open the PDF document ? IE has some problem, pls check the google groups for further assistance
Hari
 
Suresh Selvaraj
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
The error that you encountered when opening a PDF document occurs normally when the PDF file generated (either using Lowagie API or XSL-FO using FOP API) is corrupted. (Syntax problems...)
One way to verify that the PDF you generated is perfect is by replacing the PDF FILE NAME with some other PDF document that opens normally (without servlet etc) without any problems in your acrobat reader. ( You may download any PDF document from web and try it)
Good Luck.
Suresh Selvaraj
 
Scott Duncan
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
We have had several pdf problems in the past and it has been a while but it seems that this occurred when it was corrupt in some way. Try to open and then resave it with acrobat. Also, generally speaking, we had much greater success using the RequestDispatcher object to forward to the pdf in question.
One other issue it seems we were having was that when acrobat was open and performing another task, it sort of crapped out on us when trying to open it with a browser.
Hope this helps.
 
sathish kannan
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys
When i open pdf file using acrobat separately it is opening . but the problem is only when i am opening thru servlet it is saying that " File is damaged and couldnot be opened". This is the problem in IE5.0
But when i open the same file using netscape 4.7, it is perfectly opening.
How can i solve the IE5.0 problem. Do i need to set anything in the options.if so please reply me
thanks
sathish
 
Scott Duncan
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm...
cannot really help you here. My company doesn't support anything below 5.5. Can you open the PDF with IE without going throught the servlet?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!