File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes PDF USING JSF & FOP Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » JSF
Reply Bookmark "PDF USING JSF & FOP" Watch "PDF USING JSF & FOP" New topic
Author

PDF USING JSF & FOP

sharad sonapeer
Greenhorn

Joined: Jun 15, 2007
Posts: 2
Hello all,


So,I am using JSF for the first time.I am able to produce the pdf using HTML & FOP but for my project I want it using JSF.

Basically I have done till I am able to call the backing bean function which is nothing but FOP class which responses back the PDF....

But the problem I am facing with JSF is that I can see the PDF generating on the server console but I can't get it streamed to the browser JSF page where I want to see the PDF ..(Basically PDF is generated using some other XML and XSL file using FOP program and then streamed to browser...and am doing this all on localhost) ....


But instead of loading the pdf am loading the same page where I clicked the getPDF....


I am using following bean function for the response...


public void renderXML(XSLTInputHandler input,
HttpServletResponse response) throws ServletException {
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();

response.setContentType("application/pdf");

Driver driver = new Driver();
driver.setLogger(log);
driver.setRenderer(Driver.RENDER_PDF);
driver.setOutputStream(out);
driver.render(input.getParser(), input.getInputSource());

byte[] content = out.toByteArray();
response.setContentLength(content.length);
response.getOutputStream().write(content);
response.getOutputStream().flush();
} catch (Exception ex) {
throw new ServletException(ex);
}



Please anybody help me out....
This is DO OR DIE FOR ME TILL MONDAY....
Gabriel Claramunt
Ranch Hand

Joined: May 26, 2007
Posts: 375
Just use a plain old servlet redirected from your JSF screen


Gabriel
Software Surgeon
sharad sonapeer
Greenhorn

Joined: Jun 15, 2007
Posts: 2
Hey thanks Gabriel for your response,

But I am not supposed to use servlets in my application...I have to convert my servlet into backing bean as the whole application is JSF only there is no room for servlets....that's why the problem has become severe....

Please can you suggest some other wayout..???
Gabriel Claramunt
Ranch Hand

Joined: May 26, 2007
Posts: 375
Are you allowed to put the code in a JSP?
like:
<%

response.write(xmlStream)

%>

?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 13842

Even if you can do that, you have to be extremely careful about it. The whitespace that makes no difference to HTML can damage a PDF so it's unreadable. That's why a servlet would be better. Perhaps whoever made the "no servlets" decision wasn't aware that the system was going to be asked to produce PDFs, so it might be worth trying to get that decision weakened slightly.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 12513

Whoever made the "no servlets" mandate doesn't understand the full power and flexibility of JSF. Part of that power is NOT having to use JSF for parts of the webapp that are better done in other ways. JSF is not an all-or-nothing solution.


One of the most odious afflictions that Business has inflicted on the modern English language is "pro-active". Most of the time it's simply redundantly used in place of the simple old word "active". And a good deal of the rest of the time it means "You're not overworked enough yet, so go out and find more!"
 
 
subject: PDF USING JSF & FOP
 
Threads others viewed
FOP query
Rendering PDF in browser using Flying Saucer
ServletOutputStream.write not working in IE 7
Displaying PDF files on browser
404 error, can't find file using FOP, XML, XLST
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com