FOP Driver Configuration same as FOPFactory

微笑、不失礼 提交于 2019-12-06 10:28:12

问题


I am currently using FOP embedded using Driver as follows

Driver driver = new Driver();  
driver.setRenderer(Driver.RENDER_PDF);  
driver.setInputSource(new InputSource(new FileInputStream(tempout)));  
File tempFile = File.createTempFile("W2P", ".pdf");  
FileOutputStream pdfOutput = new FileOutputStream(tempFile);  
tempFile.deleteOnExit();  
driver.setOutputStream(pdfOutput);  
driver.run();  

but i would like to have access to configuration settings programatically specifically the output resolution as I have to produce multiple resolution files 72dpi 150dpi 300dpi the only way i can find of doing that is by changing to a FOPFactory as follows

FopFactory fopFactory = FopFactory.newInstance();
OutputStream out = new BufferedOutputStream(new FileOutputStream(new File("C:/Temp/myfile.pdf")));
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, out);
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(); // identity transformer
Source src = new StreamSource(new File("C:/Temp/myfile.fo"));
Result res = new SAXResult(fop.getDefaultHandler());
transformer.transform(src, res);

Is there a way of controling the FOP engine using Driver or will i have to switch to FOPFactory and what are the benefits/problems in doing so?


回答1:


The Driver class is only available in old and unmaintained versions of FOP (0.20.5 and earlier). A "new stable API" (including FopFactory) was introduced years ago. So my advice would be to use FopFactory and the latest FOP (1.0).



来源:https://stackoverflow.com/questions/5042486/fop-driver-configuration-same-as-fopfactory

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!