• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Displaying PDF files on browser

 
Ranch Hand
Posts: 452
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 427
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic