File to PDF conversion using FOP

By | July 22, 2009

FOP i.e. Formatting Objects Processor is one of the very efficient print formatter driven by XSL formatting objects. It is an application which is based on JAVA that reads a formatting object tree and then converts it to the desired output format according to the requirement and parameters we specify.

The formatting object tree can be in the form of an XML document (output by an XSLT engine like XT or Xalan) or can be passed in memory as a DOM.

Sage CRM and FOP:

Sage CRM makes use of the APACHE FOP in order to deal with all the PDF reports getting generated in CRM. This is installed by default in your C:program filesFOP folder when you do standard sage CRM installation.

Any file format to PDF using FOP:

As we have already discussed above, FOP takes various formatting object trees as an input and processes them to the desired output format for e.g. PDF.

To convert any file to PDF, you cannot go for the pure ASP coding as everything gets stuck in the user rights and IUSR doesn’t get proper permissions to access the applications across the domains. The only thing you can do is, you can make use of the DOT net technology. You can make use of either C# dot net or VB.NET code to convert your files to PDF. You can follow one of the following two methodologies.

1. Install the third party PDF conversion software (e.g. Adobe PDF Distiller, PDF995 etc.) and make a call to these printers passing your document as an input parameter to generate a PDF file from your managed code as explained above.

2. Make use of already existing FOP in your system and there is no need of any other third party tool for file to PDF conversion.

Converting any file format for e.g. Word, excel to PDF using FOP involves the two basic steps as shown in the below screenshot.

First of all we have to convert a file to the XML data format. (Note: If you are converting excel file first of all you may need to create XML map in your excel sheet.)

This XML document can be directly passed to FOP as an input parameter as per the standard functionality, but FOP throws an error as it doesn’t identify the tags in the document. For passing input to FOP, first you have to create the format of FO based tags and for that reason only we have to make use of style sheet. We can create an XSL-FO style sheet with the FO tags which collects the data from xml file created above.

We can pass both these xml and xsl files as input parameters to FOP. FOP then identifies both the files by referring styling elements from style sheet and data from xml file and passes them to the formatter.

Formatter makes use of the standard inbuilt files installed in the FOP installation directory and generates the common resultant output file as PDF document.

If you find this content useful, Please drop us an email at crm@greytrix.com.