Introduction
This article describes how to create a PDF document using XSLFO and Apache FOP. In the example I will be exporting datatable to pdf, which we need frequently.
While developing a .NET based applications, we often come to a requirement to create a PDF document. There are lots of tutorials available for exporting to Excel, Word, etc. I decided to use XSLFO and FOP for creation of PDF document.
XSLFO is XSL Formatting Objects and can be used for formatting XML data. XSL Formatting Objects, or XSL-FO, is a markup language for XML document formatting which is most often used to generate PDFs. XSL-FO is part of XSL (Extensible Stylesheet Language), a set of W3C technologies designed for the transformation and formatting of XML data. Refer http://www.w3schools.com/xslfo/xslfo_intro.asp
Apache FOP (Formatting Objects Processor) is a print formatter driven by XSL formatting objects (XSL-FO) and an output independent formatter. It is a Java application that reads a formatting object (FO) tree and renders the resulting pages to a specified output. Output formats currently supported include PDF, PS, PCL, AFP, XML (area tree representation), Print, AWT and PNG, and to a lesser extent, RTF and TXT. The primary output target is PDF. Download the latest version of FOP from the following link http://xmlgraphics.apache.org/fop/
Flow Diagram
I have also included the example of producing Datatable in PDf file. You can get the complete project @ my skydrive