Wednesday 5 November 2008

A maven2 plugin for Apache FOP

I googled for a maven2 plugin which uses Apache FOP for converting xml files into pdf files.

Since my search was not successful I made my own plugin.

Quick start:


  1. Download the source:
    $ svn co http://subversion.banapple.de/public/maven-fop-plugin

  2. Install the plugin:

    $ cd maven-fop-plugin
    $ mvn install

  3. Get some xml file and an xsl file which transforms your xml to fo. I suppose these files are now somewhere in your maven project.

  4. Configure your project to use the fop plugin:

    <plugins>
    ...
    <plugin>
    <groupId>de.banapple.mojo</groupId>
    <artifactId>maven-fop-plugin</artifactId>
    <version>1.0-SNAPSHOT</version>
    <configuration>
    <inputFiles>
    <basedir>src/main/xml</basedir>
    </inputFiles>
    <xslFile>src/main/xsl-fo/foobar-fo.xsl</xslFile>
    </configuration>
    </plugin>
    ...
    </plugins>


  5. Start maven:
    $ mvn de.banapple.mojo:maven-fop-plugin:1.0-SNAPSHOT:fop



You should now have some pdf files in the target folder.

The plugin is simple. I followed the plugin development guide.
Not documented in the development guide is the usage of the DirectoryScanner with which filesets can be defined as parameters.
The rest of the code is mostly taken from the Apache FOP documentation.

The plugin has minimal functionality and only allows to convert to pdf. Apache FOP allows a lot of other configuration which may be added in future versions of this plugin.

If you like it a comment here would be nice. If you are missing a feature please comment here, too, and I will fix it if I find the time.

The official documentation is now at www.banapple.de.

2 comments:

Hicham said...

Hi Hacim,


Thanks for publishing your work.
Two quick questions:
- have you published it to a repository, or do you know any other published maven fop plugin?
- what is the stylesheet expected in your configuration ? It works fine without it, and it is not used in the apache fop sample code you referred to.
Thanks for your help.

Hicham

Die Preetzer Abelings said...

1. it is now published on http://maven-repository.banapple.de/
2. it works without it? The xslFile configuration is required. I am referring to http://xmlgraphics.apache.org/fop/0.95/embedding.html#ExampleXML2PDF of the FOP docs.

Best regards
Hacim