Hi,

I know the Apache people have a moral obligation to recommend FOP for PDF output, but in my experience you are much better off using iText for stuff like this. It's faster, much more feature-complete, has better documentation, and the output actually looks good.

http://www.lowagie.com/iText/
http://itextdocs.lowagie.com/tutorial/

Kind regards,

Jurgen

Hansjörg Meuschel schreef:
Hi Matthias,

thanks for your help... a friend of mine also recommended FOP in between. I took a look at the api but it seems to me that FOP uses XML to generate a PDF? ! --> So how can I convert my jsf page into the required FOP-input format?? I could not find any docu to fop (except some broken links...) ?

regards,
Hans



Matthias Wessendorf wrote:

Hansjoerg,

we have worked with Apache FOP for creating pdfs. iText or
JasperReports are also lib that help you on that task.

inside of your backing bean method (referenced by a commandLink or
cmdButton) you can do somthing like this:

public String pdf() {

  FacesContext ctx = FacesContext.getCurrentInstance();

  if(!ctx.getResponseComplete()) {


      HttpServletResponse response = (HttpServletResponse)
ctx.getExternalContext().getResponse();

      byte[] file = //do some FOP, or ... stuff;

      response.setContentType("application/pdf");
      response.setHeader("Content-Disposition", "inline;
filename=\"foo.pdf\"");
      response.setContentLength(file.length);

      OutputStream out = response.getOutputStream();
      out.write(file, 0, file.length);
      out.flush();
      out.close();

      ctx.responseComplete();

  return null;
}


This will work in p(l)ain servlet or struts world too (expect of the
usage of jsf api (like FacesContext))

However, the *magic* here is the responseComplete()
<from_java_doc>
Signal the JavaServer Faces implementation that the HTTP response for
this request has already been generated (such as an HTTP redirect),
and that the request processing lifecycle should be terminated as soon
as the current phase is completed.
</from_java_doc>

and yes... it's getResponseComplete() instead of isResponseComplete()

HTH,
Matthias


On 1/15/06, Hansjörg Meuschel <[EMAIL PROTECTED]> wrote:
Hi folks,
does anybody know what is the easiest way to get a jsf page as pdf
download? Are there any libraries available for free?



--
Matthias Wessendorf
Zülpicher Wall 12, 239
50674 Köln
http://www.wessendorf.net
mwessendorf-at-gmail-dot-com


--
Among flowers, the cherry blossom.
Among men, me.

begin:vcard
fn:Jurgen Lust
n:Lust;Jurgen
org:Universiteit Gent;Directie ICT
adr:Gebouw S9;;Krijgslaan 281;Gent;O-VL;9000;Belgium
email;internet:[EMAIL PROTECTED]
title:Projectleider J2EE softwareontwikkeling
tel;work:+32-9-2648554
x-mozilla-html:TRUE
url:http://www.UGent.be
version:2.1
end:vcard

Reply via email to