File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Question for Marty Hall : pdf output from servlet ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Question for Marty Hall : pdf output from servlet ?" Watch "Question for Marty Hall : pdf output from servlet ?" New topic
Author

Question for Marty Hall : pdf output from servlet ?

Nikhil Pendharkar
Ranch Hand

Joined: Sep 01, 2003
Posts: 44
Can servlets / jsp output generate output as a .pdf file ?
If yes then how can we achieve that ?
Thanks in Advance !
Nikhil
Timothy Stone
Ranch Hand

Joined: Aug 01, 2001
Posts: 71
Binary output, is dependent on mainly the underlying OS (in the case of something like Excel) or supporting packages called by the servlet (in the case of PDF). This is at least my understanding, having never actually done it.
I have seen, especially in the XML.Apache.org site, and some related projects at Jakarta, PDF output support in XSTL. There are a number of projects doing this and the technology is most definitely servlet/jsp complementary.
I would cruise/surf over to xml.apache.org and take a look at FOP.
FOP: XSL Formatting Object processor in Java
FOP is the world's first print formatter driven by XSL formatting objects. It is a Java 1.2 application that reads a formatting object tree and then turns it into a PDF document. The formatting object tree, can be in the form of an XML document (output by an XSLT engine like Xalan) or can be passed in memory as a DOM Document or (in the case of Xalan) SAX events.


Timothy Stone, MIT, SCJP
http://www.petmystone.com/
"This Satan's drink [coffee] is so delicious, we shall cheat Satan and baptize it." --Pope Clement the VIII (1592-1605)
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
Originally posted by Nikhil Pendharkar:
Can servlets / jsp output generate output as a .pdf file ?
If yes then how can we achieve that ?
Thanks in Advance !
Nikhil

We can use setContentType("application/pdf") to send a pdf to the client's browser... I think the following link might help you...
http://www.devx.com/xml/article/16430


Co-author of SCMAD Exam Guide, Author of JMADPlus
SCJP1.2, CCNA, SCWCD1.4, SCBCD1.3, SCMAD1.0, SCJA1.0, SCJP6.0
Marty Hall
Author
Ranch Hand

Joined: Jan 02, 2003
Posts: 111
Can servlets / jsp output generate output as a .pdf file ?
If yes then how can we achieve that ?

Well, I am not quite sure which of the following two questions you are asking:
  • Assuming that I already have a program such as StyleReport or Acrobat that builds PDF, how do I use a servlet or JSP page to make it Web-accessible?
  • Are there Java packages that directly generate PDF?


  • If you are asking the former, then the answer is straightforward, as described in Section 7.2 of the book:
    1) Do
    2) Call the real PDF generation tool.
    3) Read the result using an input Stream and the binary method.
    4) Call (not -- Writers are for character-based data)
    5) Feed the binary data to the client using the method.
    BTW, you would use a servlet for this task, not a JSP page. JSP provides no advantages when generating binary data, only when generating character-based data that contains a mix of stuff you type in directly and dynamically-generated stuff.
    If you are asking the second question ("what Java packages are there that generate PDF?"), try looking at some of these sites:
  • http://xml.apache.org/fop/
  • http://www.lowagie.com/iText/
  • http://www.etymon.com/pjx/
  • http://www.inetsoft.com/inetsoft/solutions/pdf.html


  • Cheers-
    - Marty


    Java training and consulting<br /><a href="http://www.coreservlets.com/" target="_blank" rel="nofollow">http://www.coreservlets.com/</a>
    Bill Dornbush
    Greenhorn

    Joined: Jul 26, 2003
    Posts: 10
    I have used iText ( http://www.lowagie.com/iText/index.html ) to generate PDF documents from servlets and JSP pages, and it works fine.
    Bill
    Ko Ko Naing
    Ranch Hand

    Joined: Jun 08, 2002
    Posts: 3178
    Originally posted by Bill Dornbush:
    I have used iText ( http://www.lowagie.com/iText/index.html ) to generate PDF documents from servlets and JSP pages, and it works fine.
    Bill

    Hi Bill,
    The link that you provide is very useful to me as well... iText make things easy, when dealing with PDF on Servlets and JSPs... Thank you very much from me too...
    I think Nikhil got the direct solution too...
    Nikhil Pendharkar
    Ranch Hand

    Joined: Sep 01, 2003
    Posts: 44
    Thanks everyone for their valued inputs .
    I am sure the iText libs would be an intresting option to try out .
    Regards ,
    Nikhil
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Question for Marty Hall : pdf output from servlet ?
     
    Similar Threads
    Base16Format to pdf in jsp?
    Pdf to html
    XML to PDF
    Java code convention PDF?
    IReport and Barcode on PDF Output