• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

open a pdf file from a servlet

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
I need a new interior decorator. This tiny ad just painted every room in my house purple.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic