FOP驱动程序配置与FOPFactory相同 [英] FOP Driver Configuration same as FOPFactory
问题描述
我目前正在使用通过Driver嵌入的FOP,如下所示
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();
但是我想以编程方式访问配置设置,特别是输出分辨率,因为我必须生成多个分辨率文件72dpi 150dpi 300dpi 我能找到的唯一方法是按如下所示更改为FOPFactory
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);
是否可以使用驱动程序来控制FOP引擎,或者我必须切换到FOPFactory?这样做有什么好处/问题?
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?
推荐答案
Driver
类仅在FOP的旧版本和未维护版本(0.20.5和更早版本)中可用.多年前就引入了新稳定API" (包括FopFactory
).因此,我的建议是使用FopFactory
和最新的FOP(1.0).
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).
这篇关于FOP驱动程序配置与FOPFactory相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!