1 23 package org.infoglue.deliver.util.graphics; 24 25 import java.io.File ; 26 import java.io.FileOutputStream ; 27 import java.io.IOException ; 28 import java.io.StringReader ; 29 30 import org.apache.avalon.framework.logger.Logger; 31 import org.apache.fop.apps.Driver; 32 import org.apache.fop.apps.FOPException; 33 import org.xml.sax.InputSource ; 34 35 39 public class FOPHelper { 40 41 public void generatePDF(String input, File output) throws IOException , FOPException 42 { 43 FileOutputStream fileOutputStream = new FileOutputStream (output); 44 try 45 { 46 Driver driver = new Driver(); 47 Logger logger = new FOPCmsLogger(); 48 49 driver.setLogger(logger); 50 driver.setRenderer(Driver.RENDER_PDF); 51 driver.setInputSource(new InputSource (new StringReader (input))); 52 driver.setOutputStream(fileOutputStream); 53 driver.run(); 54 } 55 catch(FOPException e) 56 { 57 throw e; 58 } 59 catch(IOException e) 60 { 61 throw e; 62 } 63 finally 64 { 65 fileOutputStream.close(); 66 } 67 } 68 } 69 | Popular Tags |