public static void convertFo2Pdf(Document fo, OutputStream out) throws FileNotFoundException, FOPException, TransformerConfigurationException, TransformerException {
// Setup input stream
try {
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
// Construct fop with desired output format
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);
// Setup JAXP using identity transformer
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(); // identity transformer
// Setup input stream
JDOMSource src = new JDOMSource(fo);
// Resulting SAX events (the generated FO) must be piped through to FOP
Result res = new SAXResult(fop.getDefaultHandler());
// Start XSLT transformation and FOP processing
transformer.transform(src, res);
out.close();