Monday, December 29, 2014

Apache FOP Tutorial Part 1

FOP stands for Formatting Object processor. It's a java library which can read a formatting object (FO) tree and output the results in different formats. The output format supported are:
  • PDF
  • PS
  • PCL
  • AFP
  • XML
  • Print
  • AWT
  • PNG
And to some extent RTF and TXT. PDF is the primary output format supported by Apache FOP. Apache FOP is an alternative to iText for generating different formats.

The flow to generate a report using Apache FOP invloves using a data file in XML format. Then a XSLT style sheet is applied to generate the XSL-FO tree. The XSL-FO tree will be fed into the Apache FOP and will generate a PDF file as an output. 

Let's look into an example of how to generate a PDF file using Apache FOP

To start with let's look into the data file that we will use. Eventually the data of this file will be rendered in a pdf.

data.xml 

<?xml version="1.0"?>
<Students>
<Student>
<Name>Ishana</Name>
<Age>9</Age>
</Student>
<Student>
<Name>Ekagra</Name>
<Age>4</Age>
</Student>
<Student>
<Name>Ipsita</Name>
<Age>9</Age>
</Student>
<Student>
<Name>Akshit</Name>
<Age>3</Age>
</Student>
<Student>
<Name>Jiya</Name>
<Age>6</Age>
</Student>
</Students>

It's a XML file containing a list of students which we will use to render on a PDF file. It contains a list of students with Name and Age. 


                                                                                                                                         >>>> Part 2

No comments:

Post a Comment