The simplest way to use Driver is to instantiate it with the
InputSource and OutputStream, then set the renderer desired and
call the run method.
Here is an example use of Driver which outputs PDF:
| | |
|
Driver driver = new Driver(new InputSource (args[0]),
new FileOutputStream(args[1]));
driver.setRenderer(Driver.RENDER_PDF);
driver.run(); | |
| | |
You also need to set up logging. Global logging for all FOP
processes is managed by MessageHandler. Per-instance logging
is handled by Driver. You want to set both using an implementation
of org.apache.avalon.framework.logger.Logger. See
Jakarta
Avalon Framework for more information.
| | |
|
Logger logger = new ConsoleLogger(ConsoleLogger.LEVEL_INFO);
MessageHandler.setScreenLogger(logger);
driver.setLogger(logger); | |
| | |
To setup the user config file you can do the following
| | |
|
userConfigFile = new File(userConfig);
options = new Options(userConfigFile); | |
| | |
|
This is all you need to do, it sets up a static configuration class.
|
Once the Driver is set up, the render method
is called. Depending on whether DOM or SAX is being used, the
invocation of the method is either render(Document) or
render(Parser, InputSource) respectively.
Another possibility may be used to build the FO Tree. You can
call getContentHandler() and fire the SAX events yourself.
Once the FO Tree is built, the format() and render() methods may be
called in that order.
Here is an example use of Driver:
| | |
|
Driver driver = new Driver();
driver.setRenderer(Driver.RENDER_PDF);
driver.setInputSource(new FileInputSource(args[0]));
driver.setOutputStream(new FileOutputStream(args[1]));
driver.run(); | |
| | |
You can also specify an xml and xsl file for the input.
Here is an example use of Driver with the XSLTInputHandler:
| | |
|
Driver driver = new Driver();
driver.setRenderer(Driver.RENDER_PDF);
InputHandler inputHandler = new XSLTInputHandler(xmlFile, xslFile);
XMLReader parser = inputHandler.getParser();
driver.setOutputStream(new FileOutputStream(outFile));
driver.render(parser, inputHandler.getInputSource()); | |
| | |
Have a look at the classes CommandLineStarter or FopServlet for complete examples.
| If your FO files contain SVG then batik will be used. When batik is
initialised it uses certain classes in java.awt that
intialises the java AWT classes. This means that a daemon thread
is created by the jvm and on unix it will need to connect to a
DISPLAY.
The thread means that the java application will not automatically quit
when finished, you will need to call System.exit . These
issues should be fixed in the upcoming JDK1.4 |