Installing myfop
1. Make sure you have Java Runtime or Development Kit installed.
2. Download myfop.zip from here.
3. Extract the ZIP file.
Using myfop
1. Command line
Use myfop.bat.
2. From a Java program
public void format(String inputFile, String outputFile, String format) {
FopFactory fopFactory = FopFactory.newInstance();
// Step 2: Set up output stream.
// Note: Using BufferedOutputStream for performance reasons (helpful with FileOutputStreams).
OutputStream out = null;
try {
out = new BufferedOutputStream(new FileOutputStream(new File(outputFile)));
// Step 3: Construct fop with desired output format
Fop fop = fopFactory.newFop(format, out);
// Step 4: Setup JAXP using identity transformer
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(); // identity transformer
// Step 5: Setup input and output for XSLT transformation
// Setup input stream
//Source src = new StreamSource(new File("C:/fop-0.95/examples/fo/basic/readme.fo"));
Source src = new StreamSource(new File(inputFile));
// Resulting SAX events (the generated FO) must be piped through to FOP
Result res = new SAXResult(fop.getDefaultHandler());
// Step 6: Start XSLT transformation and FOP processing
transformer.transform(src, res);
} catch (Exception e) {
e.printStackTrace();
} finally {
//Clean-up
if (out != null)
try {
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}