You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Hansjörg Meuschel <hj...@gmx.de> on 2006/01/15 11:19:59 UTC

easiest way to get a jsf page as pdf download

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?

Re: easiest way to get a jsf page as pdf download

Posted by Hansjörg Meuschel <hj...@gmx.de>.
I'm just looking ... and getting convinced :-)

Simon Kitching wrote:

>If you want to specifically generate a report, another option to look at
>is jasper:
>  http://jasperreports.sourceforge.net/
>
>
>On Tue, 2006-01-17 at 10:30 +0100, Hansjörg Meuschel wrote:
>  
>
>>Hi again,
>>actually what I want is to generate a report from the database and not a 
>>pdf that looks like the html ..
>>I just thought the easiest way would be to transform the gnereated html 
>>page directly into pdf which seems to be impossible...
>>So I'll take a look at both projects and see ...
>>
>>Thanks for your help again!
>>
>>Regards,
>>Hans
>>
>>
>>Simon Kitching wrote:
>>
>>    
>>
>>>Hi Hans,
>>>
>>>What Matthias describes below is where you have a JSF page, and you want
>>>a button labelled "generate report" or similar that creates some kind of
>>>PDF document then serves it up to the user's browser. But that PDF isn't
>>>"a picture of the current page", it's a PDF generated using data pulled
>>>      
>>>
>>>from a database or something like that. If that's really what you are
>>    
>>
>>>after then FOP is a good tool for that; your java code creates some xml
>>>using the FO schema, then feeds it to the FOP library. Nothing to do
>>>with JSF though.
>>>
>>>There is no way to "generate a pdf that looks like my html screen" from
>>>java code which I believe is what you want to do. Some browsers provide
>>>a "print page" option, and some operating systems provide a "print to
>>>PDF" option in the print dialog so that's one way of creating a PDF that
>>>contains the current page but it's manual.
>>>
>>>The FOP project is here:
>>> http://xmlgraphics.apache.org/fop/
>>>
>>>Regards,
>>>
>>>Simon
>>>
>>>
>>>
>>>
>>>On Tue, 2006-01-17 at 09:58 +0100, Hansjörg Meuschel wrote:
>>> 
>>>
>>>      
>>>
>>>>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 <hj...@gmx.de> 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
>>>>>
>>>>>
>>>>>     
>>>>>
>>>>>          
>>>>>
>>> 
>>>
>>>      
>>>
>>    
>>
>
>
>  
>


-- 
Mit freundlichen Grüßen,

------------------------------
 Hansjörg Meuschel
 Martin-Treu-Str. 40
 90403 Nürnberg
 Tel.   +49 (0)911 274 278 1
 mobil: +49 (1)60 725 3479
 mail:  hjmeu@gmx.de
 http://www.meuschel.net


Re: easiest way to get a jsf page as pdf download

Posted by Simon Kitching <sk...@apache.org>.
If you want to specifically generate a report, another option to look at
is jasper:
  http://jasperreports.sourceforge.net/


On Tue, 2006-01-17 at 10:30 +0100, Hansjörg Meuschel wrote:
> Hi again,
> actually what I want is to generate a report from the database and not a 
> pdf that looks like the html ..
> I just thought the easiest way would be to transform the gnereated html 
> page directly into pdf which seems to be impossible...
> So I'll take a look at both projects and see ...
> 
> Thanks for your help again!
> 
> Regards,
> Hans
> 
> 
> Simon Kitching wrote:
> 
> >Hi Hans,
> >
> >What Matthias describes below is where you have a JSF page, and you want
> >a button labelled "generate report" or similar that creates some kind of
> >PDF document then serves it up to the user's browser. But that PDF isn't
> >"a picture of the current page", it's a PDF generated using data pulled
> >from a database or something like that. If that's really what you are
> >after then FOP is a good tool for that; your java code creates some xml
> >using the FO schema, then feeds it to the FOP library. Nothing to do
> >with JSF though.
> >
> >There is no way to "generate a pdf that looks like my html screen" from
> >java code which I believe is what you want to do. Some browsers provide
> >a "print page" option, and some operating systems provide a "print to
> >PDF" option in the print dialog so that's one way of creating a PDF that
> >contains the current page but it's manual.
> >
> >The FOP project is here:
> >  http://xmlgraphics.apache.org/fop/
> >
> >Regards,
> >
> >Simon
> >
> >
> >
> >
> >On Tue, 2006-01-17 at 09:58 +0100, Hansjörg Meuschel wrote:
> >  
> >
> >>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 <hj...@gmx.de> 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
> >>> 
> >>>
> >>>      
> >>>
> >
> >
> >  
> >
> 
> 


Re: easiest way to get a jsf page as pdf download

Posted by Hansjörg Meuschel <hj...@gmx.de>.
Hi again,
actually what I want is to generate a report from the database and not a 
pdf that looks like the html ..
I just thought the easiest way would be to transform the gnereated html 
page directly into pdf which seems to be impossible...
So I'll take a look at both projects and see ...

Thanks for your help again!

Regards,
Hans


Simon Kitching wrote:

>Hi Hans,
>
>What Matthias describes below is where you have a JSF page, and you want
>a button labelled "generate report" or similar that creates some kind of
>PDF document then serves it up to the user's browser. But that PDF isn't
>"a picture of the current page", it's a PDF generated using data pulled
>from a database or something like that. If that's really what you are
>after then FOP is a good tool for that; your java code creates some xml
>using the FO schema, then feeds it to the FOP library. Nothing to do
>with JSF though.
>
>There is no way to "generate a pdf that looks like my html screen" from
>java code which I believe is what you want to do. Some browsers provide
>a "print page" option, and some operating systems provide a "print to
>PDF" option in the print dialog so that's one way of creating a PDF that
>contains the current page but it's manual.
>
>The FOP project is here:
>  http://xmlgraphics.apache.org/fop/
>
>Regards,
>
>Simon
>
>
>
>
>On Tue, 2006-01-17 at 09:58 +0100, Hansjörg Meuschel wrote:
>  
>
>>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 <hj...@gmx.de> 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
>>> 
>>>
>>>      
>>>
>
>
>  
>


-- 
Mit freundlichen Grüßen,

------------------------------
 Hansjörg Meuschel
 Martin-Treu-Str. 40
 90403 Nürnberg
 Tel.   +49 (0)911 274 278 1
 mobil: +49 (1)60 725 3479
 mail:  hjmeu@gmx.de
 http://www.meuschel.net


Re: easiest way to get a jsf page as pdf download

Posted by Jurgen Lust <Ju...@UGent.be>.
Indeed. UIInput components don't make much sense in a PDF environment i 
think (although technically possible).
I already have iText code for rendering a PDF version of the schedule 
component, although not yet converted to JSF...

Jurgen

Matthias Wessendorf schreef:
> for something like UIData is make pretty sense to me
>
> On 1/17/06, Jurgen Lust <Ju...@ugent.be> wrote:
>   
>>  I would definitely write pdf renderers for some components if other people
>> want to help...
>>
>>  Jurgen
>>
>>  Matthias Wessendorf schreef:
>>  Right Juergen!
>>
>> would you like to volunteer ? :-)
>>
>> SpringMVC has some *pdf* based rendering stuff.
>>
>> -Matthias
>>
>> On 1/17/06, Jurgen Lust <Ju...@ugent.be> wrote:
>>
>>
>>  Theoretically, you could write a new RenderKit which renders a JSF page to
>> PDF instead of HTML. It would probably even work with AcroForms...
>>
>>  Jurgen
>>
>>  Simon Kitching schreef:
>>  Hi Hans,
>>
>> What Matthias describes below is where you have a JSF page, and you want
>> a button labelled "generate report" or similar that creates some kind of
>> PDF document then serves it up to the user's browser. But that PDF isn't
>> "a picture of the current page", it's a PDF generated using data pulled
>> from a database or something like that. If that's really what you are
>> after then FOP is a good tool for that; your java code creates some xml
>> using the FO schema, then feeds it to the FOP library. Nothing to do
>> with JSF though.
>>
>> There is no way to "generate a pdf that looks like my html screen" from
>> java code which I believe is what you want to do. Some browsers provide
>> a "print page" option, and some operating systems provide a "print to
>> PDF" option in the print dialog so that's one way of creating a PDF that
>> contains the current page but it's manual.
>>
>> The FOP project is here:
>>  http://xmlgraphics.apache.org/fop/
>>
>> Regards,
>>
>> Simon
>>
>>
>>
>>
>> On Tue, 2006-01-17 at 09:58 +0100, Hansj�rg Meuschel wrote:
>>
>>
>>  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 <hj...@gmx.de> 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.
>>
>>
>>
>>
>>
>> --
>> 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.
>>
>>
>>
>>     
>
>
> --
> 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.


Re: easiest way to get a jsf page as pdf download

Posted by "::SammyRulez::" <sa...@gmail.com>.
I recently developed an action to export dataTables in excel files via POI.

just get the content of the dataTable in the managed-bean and build
your report and after use the responsecomplete method.

see http://www.jsffaq.com/ on how to do this



2006/1/17, Simon Kitching <sk...@apache.org>:
> Hmm..
>
> It should be possible to define a JSP tag which extends the tomahawk
> HtmlDataTableTag class except that getRendererType returns a different
> value. An entry in faces-config.xml could then map this to a custom
> Renderer class that generates an inline embedded PDF. A page could then
> use this as:
>
> <z:pdfDataTable ....>
> </z:pdfDataTable>
>
> The user could (I presume) then click "save as" to save it.
>
> That sounds rather interesting! Not a complete pdf rendering suite, just
> a few chosen components. [NB: I'm not volunteering to help; just saying
> it sounds useful!].
>
> It would be a little tricky to bundle this in tomahawk, however. It
> would not be desirable to declare itext (or fop) as a dependency of
> tomahawk just because one component needs it. Perhaps maven needs some
> way to express "class X has a dependency on library Y", so that this
> sort of thing can be done.  The FileUpload component also falls into
> this category.
>
> License issues might be tricky too; itext is under MPL/LGPL. I know
> there are some issues with LGPL, not sure about MPL. The jsfcomp project
> could be a home for it though.
>
> A complete PDF RenderKit using AcroForms *would* be kind of cute.
> However I think there are higher priority issues :-)
>
> Cheers,
>
> Simon
>
>
> On Tue, 2006-01-17 at 11:21 +0100, Matthias Wessendorf wrote:
> > for something like UIData is make pretty sense to me
> >
> > On 1/17/06, Jurgen Lust <Ju...@ugent.be> wrote:
> > >  I would definitely write pdf renderers for some components if other people
> > > want to help...
> > >
> > >  Jurgen
> > >
> > >  Matthias Wessendorf schreef:
> > >  Right Juergen!
> > >
> > > would you like to volunteer ? :-)
> > >
> > > SpringMVC has some *pdf* based rendering stuff.
> > >
> > > -Matthias
> > >
> > > On 1/17/06, Jurgen Lust <Ju...@ugent.be> wrote:
> > >
> > >
> > >  Theoretically, you could write a new RenderKit which renders a JSF page to
> > > PDF instead of HTML. It would probably even work with AcroForms...
> > >
> > >  Jurgen
> > >
> > >  Simon Kitching schreef:
> > >  Hi Hans,
> > >
> > > What Matthias describes below is where you have a JSF page, and you want
> > > a button labelled "generate report" or similar that creates some kind of
> > > PDF document then serves it up to the user's browser. But that PDF isn't
> > > "a picture of the current page", it's a PDF generated using data pulled
> > > from a database or something like that. If that's really what you are
> > > after then FOP is a good tool for that; your java code creates some xml
> > > using the FO schema, then feeds it to the FOP library. Nothing to do
> > > with JSF though.
> > >
> > > There is no way to "generate a pdf that looks like my html screen" from
> > > java code which I believe is what you want to do. Some browsers provide
> > > a "print page" option, and some operating systems provide a "print to
> > > PDF" option in the print dialog so that's one way of creating a PDF that
> > > contains the current page but it's manual.
> > >
> > > The FOP project is here:
> > >  http://xmlgraphics.apache.org/fop/
> > >
> > > Regards,
> > >
> > > Simon
> > >
> > >
> > >
> > >
> > > On Tue, 2006-01-17 at 09:58 +0100, Hansjörg Meuschel wrote:
> > >
> > >
> > >  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 <hj...@gmx.de> 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.
> > >
> > >
> > >
> > >
> > >
> > > --
> > > 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.
> > >
> > >
> > >
> >
> >
> > --
> > Matthias Wessendorf
> > Zülpicher Wall 12, 239
> > 50674 Köln
> > http://www.wessendorf.net
> > mwessendorf-at-gmail-dot-com
>
>


--
::SammyRulez::
http://sammyprojectz.blogspot.com

Re: easiest way to get a jsf page as pdf download

Posted by Simon Kitching <sk...@apache.org>.
Hmm..

It should be possible to define a JSP tag which extends the tomahawk
HtmlDataTableTag class except that getRendererType returns a different
value. An entry in faces-config.xml could then map this to a custom
Renderer class that generates an inline embedded PDF. A page could then
use this as:

<z:pdfDataTable ....>
</z:pdfDataTable>

The user could (I presume) then click "save as" to save it.

That sounds rather interesting! Not a complete pdf rendering suite, just
a few chosen components. [NB: I'm not volunteering to help; just saying
it sounds useful!].

It would be a little tricky to bundle this in tomahawk, however. It
would not be desirable to declare itext (or fop) as a dependency of
tomahawk just because one component needs it. Perhaps maven needs some
way to express "class X has a dependency on library Y", so that this
sort of thing can be done.  The FileUpload component also falls into
this category.

License issues might be tricky too; itext is under MPL/LGPL. I know
there are some issues with LGPL, not sure about MPL. The jsfcomp project
could be a home for it though.

A complete PDF RenderKit using AcroForms *would* be kind of cute.
However I think there are higher priority issues :-)

Cheers,

Simon


On Tue, 2006-01-17 at 11:21 +0100, Matthias Wessendorf wrote:
> for something like UIData is make pretty sense to me
> 
> On 1/17/06, Jurgen Lust <Ju...@ugent.be> wrote:
> >  I would definitely write pdf renderers for some components if other people
> > want to help...
> >
> >  Jurgen
> >
> >  Matthias Wessendorf schreef:
> >  Right Juergen!
> >
> > would you like to volunteer ? :-)
> >
> > SpringMVC has some *pdf* based rendering stuff.
> >
> > -Matthias
> >
> > On 1/17/06, Jurgen Lust <Ju...@ugent.be> wrote:
> >
> >
> >  Theoretically, you could write a new RenderKit which renders a JSF page to
> > PDF instead of HTML. It would probably even work with AcroForms...
> >
> >  Jurgen
> >
> >  Simon Kitching schreef:
> >  Hi Hans,
> >
> > What Matthias describes below is where you have a JSF page, and you want
> > a button labelled "generate report" or similar that creates some kind of
> > PDF document then serves it up to the user's browser. But that PDF isn't
> > "a picture of the current page", it's a PDF generated using data pulled
> > from a database or something like that. If that's really what you are
> > after then FOP is a good tool for that; your java code creates some xml
> > using the FO schema, then feeds it to the FOP library. Nothing to do
> > with JSF though.
> >
> > There is no way to "generate a pdf that looks like my html screen" from
> > java code which I believe is what you want to do. Some browsers provide
> > a "print page" option, and some operating systems provide a "print to
> > PDF" option in the print dialog so that's one way of creating a PDF that
> > contains the current page but it's manual.
> >
> > The FOP project is here:
> >  http://xmlgraphics.apache.org/fop/
> >
> > Regards,
> >
> > Simon
> >
> >
> >
> >
> > On Tue, 2006-01-17 at 09:58 +0100, Hansjörg Meuschel wrote:
> >
> >
> >  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 <hj...@gmx.de> 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.
> >
> >
> >
> >
> >
> > --
> > 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.
> >
> >
> >
> 
> 
> --
> Matthias Wessendorf
> Zülpicher Wall 12, 239
> 50674 Köln
> http://www.wessendorf.net
> mwessendorf-at-gmail-dot-com


Re: easiest way to get a jsf page as pdf download

Posted by Matthias Wessendorf <mw...@gmail.com>.
for something like UIData is make pretty sense to me

On 1/17/06, Jurgen Lust <Ju...@ugent.be> wrote:
>  I would definitely write pdf renderers for some components if other people
> want to help...
>
>  Jurgen
>
>  Matthias Wessendorf schreef:
>  Right Juergen!
>
> would you like to volunteer ? :-)
>
> SpringMVC has some *pdf* based rendering stuff.
>
> -Matthias
>
> On 1/17/06, Jurgen Lust <Ju...@ugent.be> wrote:
>
>
>  Theoretically, you could write a new RenderKit which renders a JSF page to
> PDF instead of HTML. It would probably even work with AcroForms...
>
>  Jurgen
>
>  Simon Kitching schreef:
>  Hi Hans,
>
> What Matthias describes below is where you have a JSF page, and you want
> a button labelled "generate report" or similar that creates some kind of
> PDF document then serves it up to the user's browser. But that PDF isn't
> "a picture of the current page", it's a PDF generated using data pulled
> from a database or something like that. If that's really what you are
> after then FOP is a good tool for that; your java code creates some xml
> using the FO schema, then feeds it to the FOP library. Nothing to do
> with JSF though.
>
> There is no way to "generate a pdf that looks like my html screen" from
> java code which I believe is what you want to do. Some browsers provide
> a "print page" option, and some operating systems provide a "print to
> PDF" option in the print dialog so that's one way of creating a PDF that
> contains the current page but it's manual.
>
> The FOP project is here:
>  http://xmlgraphics.apache.org/fop/
>
> Regards,
>
> Simon
>
>
>
>
> On Tue, 2006-01-17 at 09:58 +0100, Hansjörg Meuschel wrote:
>
>
>  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 <hj...@gmx.de> 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.
>
>
>
>
>
> --
> 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.
>
>
>


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

Re: easiest way to get a jsf page as pdf download

Posted by Jurgen Lust <Ju...@UGent.be>.
I would definitely write pdf renderers for some components if other 
people want to help...

Jurgen

Matthias Wessendorf schreef:
> Right Juergen!
>
> would you like to volunteer ? :-)
>
> SpringMVC has some *pdf* based rendering stuff.
>
> -Matthias
>
> On 1/17/06, Jurgen Lust <Ju...@ugent.be> wrote:
>   
>>  Theoretically, you could write a new RenderKit which renders a JSF page to
>> PDF instead of HTML. It would probably even work with AcroForms...
>>
>>  Jurgen
>>
>>  Simon Kitching schreef:
>>  Hi Hans,
>>
>> What Matthias describes below is where you have a JSF page, and you want
>> a button labelled "generate report" or similar that creates some kind of
>> PDF document then serves it up to the user's browser. But that PDF isn't
>> "a picture of the current page", it's a PDF generated using data pulled
>> from a database or something like that. If that's really what you are
>> after then FOP is a good tool for that; your java code creates some xml
>> using the FO schema, then feeds it to the FOP library. Nothing to do
>> with JSF though.
>>
>> There is no way to "generate a pdf that looks like my html screen" from
>> java code which I believe is what you want to do. Some browsers provide
>> a "print page" option, and some operating systems provide a "print to
>> PDF" option in the print dialog so that's one way of creating a PDF that
>> contains the current page but it's manual.
>>
>> The FOP project is here:
>>  http://xmlgraphics.apache.org/fop/
>>
>> Regards,
>>
>> Simon
>>
>>
>>
>>
>> On Tue, 2006-01-17 at 09:58 +0100, Hansj�rg Meuschel wrote:
>>
>>
>>  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 <hj...@gmx.de> 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.
>>
>>
>>
>>     
>
>
> --
> 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.


Re: easiest way to get a jsf page as pdf download

Posted by Matthias Wessendorf <mw...@gmail.com>.
Right Juergen!

would you like to volunteer ? :-)

SpringMVC has some *pdf* based rendering stuff.

-Matthias

On 1/17/06, Jurgen Lust <Ju...@ugent.be> wrote:
>  Theoretically, you could write a new RenderKit which renders a JSF page to
> PDF instead of HTML. It would probably even work with AcroForms...
>
>  Jurgen
>
>  Simon Kitching schreef:
>  Hi Hans,
>
> What Matthias describes below is where you have a JSF page, and you want
> a button labelled "generate report" or similar that creates some kind of
> PDF document then serves it up to the user's browser. But that PDF isn't
> "a picture of the current page", it's a PDF generated using data pulled
> from a database or something like that. If that's really what you are
> after then FOP is a good tool for that; your java code creates some xml
> using the FO schema, then feeds it to the FOP library. Nothing to do
> with JSF though.
>
> There is no way to "generate a pdf that looks like my html screen" from
> java code which I believe is what you want to do. Some browsers provide
> a "print page" option, and some operating systems provide a "print to
> PDF" option in the print dialog so that's one way of creating a PDF that
> contains the current page but it's manual.
>
> The FOP project is here:
>  http://xmlgraphics.apache.org/fop/
>
> Regards,
>
> Simon
>
>
>
>
> On Tue, 2006-01-17 at 09:58 +0100, Hansjörg Meuschel wrote:
>
>
>  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 <hj...@gmx.de> 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.
>
>
>


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

Re: easiest way to get a jsf page as pdf download

Posted by Jurgen Lust <Ju...@UGent.be>.
Theoretically, you could write a new RenderKit which renders a JSF page 
to PDF instead of HTML. It would probably even work with AcroForms...

Jurgen

Simon Kitching schreef:
> Hi Hans,
>
> What Matthias describes below is where you have a JSF page, and you want
> a button labelled "generate report" or similar that creates some kind of
> PDF document then serves it up to the user's browser. But that PDF isn't
> "a picture of the current page", it's a PDF generated using data pulled
> from a database or something like that. If that's really what you are
> after then FOP is a good tool for that; your java code creates some xml
> using the FO schema, then feeds it to the FOP library. Nothing to do
> with JSF though.
>
> There is no way to "generate a pdf that looks like my html screen" from
> java code which I believe is what you want to do. Some browsers provide
> a "print page" option, and some operating systems provide a "print to
> PDF" option in the print dialog so that's one way of creating a PDF that
> contains the current page but it's manual.
>
> The FOP project is here:
>   http://xmlgraphics.apache.org/fop/
>
> Regards,
>
> Simon
>
>
>
>
> On Tue, 2006-01-17 at 09:58 +0100, Hansj�rg Meuschel wrote:
>   
>> 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 <hj...@gmx.de> 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.


Re: easiest way to get a jsf page as pdf download

Posted by Simon Kitching <sk...@apache.org>.
Hi Hans,

What Matthias describes below is where you have a JSF page, and you want
a button labelled "generate report" or similar that creates some kind of
PDF document then serves it up to the user's browser. But that PDF isn't
"a picture of the current page", it's a PDF generated using data pulled
from a database or something like that. If that's really what you are
after then FOP is a good tool for that; your java code creates some xml
using the FO schema, then feeds it to the FOP library. Nothing to do
with JSF though.

There is no way to "generate a pdf that looks like my html screen" from
java code which I believe is what you want to do. Some browsers provide
a "print page" option, and some operating systems provide a "print to
PDF" option in the print dialog so that's one way of creating a PDF that
contains the current page but it's manual.

The FOP project is here:
  http://xmlgraphics.apache.org/fop/

Regards,

Simon




On Tue, 2006-01-17 at 09:58 +0100, Hansjörg Meuschel wrote:
> 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 <hj...@gmx.de> 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
> >  
> >


Re: easiest way to get a jsf page as pdf download

Posted by Jurgen Lust <Ju...@UGent.be>.
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 <hj...@gmx.de> 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.


Re: easiest way to get a jsf page as pdf download

Posted by Hansjörg Meuschel <hj...@gmx.de>.
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 <hj...@gmx.de> 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
>  
>

Re: easiest way to get a jsf page as pdf download

Posted by Matthias Wessendorf <mw...@gmail.com>.
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 <hj...@gmx.de> 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

Re: easiest way to get a jsf page as pdf download

Posted by Hansjörg Meuschel <hj...@gmx.de>.
Wow, birt looks interesting too! I'm actually using Eclipse for 
development...
thanks!

Werner Punz wrote:

>Hansjörg Meuschel schrieb:
>  
>
>>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?
>>
>>    
>>
>standard reporting stuff, use itext, jasper reports, or the eclipse
>subproject birt, which can handle pdf easily...
>
t


Re: easiest way to get a jsf page as pdf download

Posted by Werner Punz <we...@gmx.at>.
Hansjörg Meuschel schrieb:
> 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?
> 
standard reporting stuff, use itext, jasper reports, or the eclipse
subproject birt, which can handle pdf easily...