Converting XSL-FO to PDF
In this section, we will convert the XSL-FO document generated in the previous section to a PDF document using the FOP driver. In the Java application XMLToPDF.java
, import the FOP Driver class and the logger classes required to convert an XML document to a PDF document.
import org.apache.fop.apps.Driver; import org.apache.avalon.framework.logger.Logger; import org.apache.avalon.framework.logger.ConsoleLogger;
Creating the FOP driver
Create an FOP driver object using the constructor for the Driver
class.
Driver driver=new Driver();
Create a logger with level setting LEVEL_INFO
using the ConsoleLogger
constructor.
Logger logger=new ConsoleLogger(ConsoleLogger.LEVEL_INFO);
Set the logger on the FOP driver using the setLogger
method, and set the logger on the MessageHandler
using the setScreenLogger
method.
driver.setLogger(logger); org.apache.fop.messaging.MessageHandler.setScreenLogger(logger);
Set the renderer for the FOP driver using the setRenderer
method. For conversion...