• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Displaying PDF files on browser

 
Prakash Dwivedi
Ranch Hand
Posts: 452
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
I want to show PDF file in the browser, while i am able to show the pdf file while i am hard-coding the name of the pdf file(like C:\abc.pdf), the same code doesn't work when i am specifying the file name at runtime, Intrestingly the same code(specifying file name at runtime) works in Netscape 7.0, while it doesn't work on other browsers(not even at Netscape 6). In IE 6 it opens Adobe Acrobat Reader, but than it throws the error "Can't open file,***.fdf"(*** keeps changing).I am able to view other pdf documents, from other sites on IE(so the problem is not in IE setting, i believe). I am attaching my code, I will be very thankful if anybody can help

Thanks
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good question. I have been dabbling myself in PDFs from Servlets but haven't had much luck or really time to get it to actually work. I was actually using XML with XSTL and XSL:FO with Apache's Fop, it says you can create PDFs dynamically without saving the actual PDF file.
It looks like you already have the PDF file on your Web server.
I have seen another product that I thought looked really good, but again you would be making the PDF on the fly. But that product was iText, I think that was the name of the product.

FOP has a Driver class that can be used to take a PDF file and send it to the Output stream.

Not sure fi that will help you in any particular way, but I thought I'd throw my 2 cents worth in.
Mark
 
Ryan Bailey
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
XML with XSTL and XSL:FO with Apache's Fop works great for creating PDF files on the fly. I will be using that in a production environment. Using XSL:FO is great when you need to apply a stylesheet to an xml file. Are you dealing with xml? If not, then using XSL:FO might be an over kill since you have to parse the xml file, and then run it through Apache's FOP processer. I am storing the file but as Mark mentioned there is a while to generate an OutputStream and send that stream to the response.
I ran into a problem like this before. Try saving your results to a ByteArrayOutputStream and sending that to the OutputStream. For some reason bytes were being lost when I did it any other way.
Good luck,
Ryan
 
Sean Sullivan
Ranch Hand
Posts: 427
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wrote this article about PDF's, Java servlets, and iText
http://www.onjava.com/pub/a/onjava/2003/06/18/dynamic_files.html
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic