//Setup fonts and user agent
FontInfo fontInfo = new FontInfo();
FOUserAgent userAgent = fopFactory.newFOUserAgent();
//Construct the AreaTreeModel that will received the individual pages
AreaTreeModel treeModel = new RenderPagesModel(userAgent,
MimeConstants.MIME_PDF, fontInfo, out);
//Iterate over all intermediate files
AreaTreeParser parser = new AreaTreeParser();
Source src = new StreamSource(atfile);
Source xslt = new StreamSource(stampSheet);
//Setup Transformer for XSLT processing
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer(xslt);
//Send XSLT result to AreaTreeParser
SAXResult res = new SAXResult(parser.getContentHandler(treeModel, userAgent));
//Start XSLT transformation and area tree parsing
transformer.transform(src, res);
//Signal the end of the processing. The renderer can finalize the target document.
treeModel.endDocument();
} finally {
out.close();
}
}