Example: Converting XSL FO source data to a PDF

Note: Read the Code example disclaimer for important legal information.
///////////////////////////////////////////////////////////////////////////////
// 
// Example: Converting XSL FO source to a PDF.
//
// This program uses the IBM Toolbox for Java ReportWriter classes to convert
// XSL FO source data (created by using HTMLDocument) to a PDF.
//
// This example requires the following.jars to be in the classpath.
//
//   composer.jar
//   outputwriters.jar 
//   reportwriter.jar
//   x4j400.jar
//   xslparser.jar
//
// These jars are part of the IBM ToolBox for Java, and reside in directory
// /QIBM/ProdData/HTTP/Public/jt400/lib on your server.
//
// Command syntax: 
//    ProcessXslFo FOfilename PDFfilename
//
///////////////////////////////////////////////////////////////////////////////


import java.io.FileInputStream;
import java.io.FileOutputStream;

import java.awt.print.Paper;
import java.awt.print.PageFormat;

import org.w3c.dom.Document;

import com.ibm.xsl.composer.framework.Context;

import com.ibm.as400.util.reportwriter.pdfwriter.PDFContext;
import com.ibm.as400.util.reportwriter.processor.XSLReportProcessor;

public class ProcessXslFo
{
    public static void main(String args[])
    {
        if (args.length != 2)
        {
            System.out.println("Usage:  java ProcessXslFo <fo file name> <pdf file name>");
            System.exit(0);
        }

        try
        {
            String inName = args[0];
            String outName = args[1];

            /* Input. File containing XML FO. */
            FileInputStream fin = null;

            /* Output. Which in this example will be PDF. */
            FileOutputStream fout = null;

            try
            {
                fin  = new FileInputStream(inName);
                fout = new FileOutputStream(outName);
            }
            catch (Exception e)
            {
                e.printStackTrace();
                System.exit(0);
            }

            /*
            * Setup Page format.
            */
            Paper paper = new Paper();
            paper.setSize(612, 792);
            paper.setImageableArea(0, 0, 756, 936);

            PageFormat pageFormat = new PageFormat();
            pageFormat.setPaper(paper);

            /*
            * Create a PDF context. Set output file name.
            */
            PDFContext pdfContext = new PDFContext(fout, pageFormat);

            /*
            * Create XSLReportProcessor instance.
            */
            XSLReportProcessor report = new XSLReportProcessor(pdfContext);

            /* 
            * Open XML FO source.
            */
            try
            {
                report.setXSLFOSource(fin);
            }
            catch (Exception e)
            {
                e.printStackTrace();
                System.exit(0);
            }

            /* 
            * Process the report.
            */
            try
            {
                report.processReport();
            }
            catch (Exception e)
            {
                e.printStackTrace();
                System.exit(0);
            }
        }
        catch (Exception e)
        {
            e.printStackTrace();
            System.exit(0);
        }

        /* exit */
        System.exit(0);
    }
}