Access Keys:
Skip to content (Access Key - 0)

Apache FOP Transformer

The Apache FOP Transformer was created to transform a source message into formats supported by the Apache FOP project. The initial need stemmed from a business requirement to build PDF documents on the fly from database records. After some thought, it made sense to incorporate the FOP API in order to make the transformer more flexible.

The project is currently in the beta stage. Although the downloads show a 1.0 version, the 0.0.2 version is correct. The code is very basic and the output has only been tested with PDF and Text documents.

Installation Instructions

There are no special installation instructions required. Simply add the JAR file to your classpath and configure Mule using the examples below.

Usage

The transformer uses code from the Apache FOP project, as well as an XSL-FO formatted source document (either String or ByteArray) to produce a message in one of the following formats: PDF, PS, PCL, AFP, XML (area tree representation), Print, AWT and PNG, RTF, and TXT.

Properties

The following properties can be configured on the transformer:

Property Description
foFile The path of the file that contains the XSL-FO document. This file will use the source document as input to build the target message.
mimeType The MIME type of the output. This can be one of the following:

application/x-afp
application/vnd.ibm.modcap
application/postscript
application/X-fop-areatree
application/X-fop-awt-preview
application/X-fop-print
image/gif
image/jpeg
application/mif
application/x-pcl
application/vnd.hp-PCL
application/pdf
text/plain
image/png
application/postscript
application/rtf
text/richtext
text/rtf
image/svg+xml
image/tiff
text/xsl

The transformer is configured in the Mule configuration XML (mule-config.xml) as:

<transformer name="XslFoTransformer" className="org.mule.transformers.fop.XslFoTransformer">
  <properties>
    <property name="foFile" value="{path to XSL-FO file}"/>
    <property name="mimeType" value="{MIME type value from above}"/>
  </properties>
</transformer>

NOTE:The two properties are given in the sample, but are not required. If the foFile properties is omitted, the source message must be an XSL-FO XML document.

Example

Excerpt from mule-config.xml 

<transformer name="XslFoToPdf" className="org.mule.transformers.fop.XslFoTransformer">
  <properties>
    <property name="foFile" value="/home/erich/workspace/ActionLinkEsb/xsl/xml-to-fo.xsl"/>
  </properties>
</transformer>

xml-to-fo.xsl

<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:fo="http://www.w3.org/1999/XSL/Format"
  version="1.0">
  <xsl:template match="/">
    <fo:root >
      <fo:layout-master-set>
        <fo:simple-page-master master-name="A4">
          <fo:region-body />
        </fo:simple-page-master>
      </fo:layout-master-set>
      <fo:page-sequence master-reference="A4">
        <fo:flow flow-name="xsl-region-body">
          <fo:block>
            <fo:table>
              <xsl:for-each select="/root/*">
                <fo:table-column />
              </xsl:for-each>
              <fo:table-header>
                <fo:table-row>
                  <xsl:for-each select="/root/*">
                    <fo:table-cell>
                      <fo:block  font-weight="bold"><xsl:value-of select="name()"/></fo:block>
                    </fo:table-cell>
                  </xsl:for-each>
                </fo:table-row>
              </fo:table-header>
              <fo:table-body>
                <fo:table-row>
                  <xsl:for-each select="/root/*">
                    <fo:table-cell>
                      <fo:block><xsl:value-of select="current()"/></fo:block>
                    </fo:table-cell>
                  </xsl:for-each>
                </fo:table-row>
              </fo:table-body>
            </fo:table>
          </fo:block>
        </fo:flow>
      </fo:page-sequence>
    </fo:root>
  </xsl:template>
</xsl:stylesheet>



Adaptavist Theme Builder (3.3.3-conf210) Powered by Atlassian Confluence 2.10, the Enterprise Wiki.
Free theme builder license