Skip to main content

Exporting PDF using JSF 2.1

Posted by mriem on November 11, 2011 at 5:50 AM PST

In the previous blog article we generated XSL:FO, this was really
a springboard for the real stuff. In this blog article we show how
you can now generate PDFs straight from a JSF page. How? Read on!

  1. Install the JSF FOP JAR file.
  2. Create a JSF page with the proper render kit id and content type
  3. Demo it!

Install the JSF FOP JAR file

If you are non-Maven user you will need to download the JAR file manually from
http://www.manorrock.com/repo/com/manorrock/jsf/com-manorrock-jsf-fop/.
And copy it into your WEB-INF/lib directory.
 

If you are a Maven user use the following dependency:

<dependency>
  <groupId>com.manorrock.jsf</groupId>
  <artifactId>com-manorrock-jsf-fop</artifactId>
  <version>2.0.1</version>
</dependency>

Create the JSF page with the proper render kit id and content type
 

 <f:view 
    renderKitId="FOP"
    contentType="application/pdf"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html">
  <h:body>
    <h:outputText value="This is rendered using FOP"/>
  </h:body>
</f:view>

Demo it!
 

And head on over to http://www.manorrock.com/demo/jsf/fop/ to see it in action!