FOP 驱动配置与 FOPFactory 相同 [英] FOP Driver Configuration same as FOPFactory
问题描述
我目前正在使用以下使用驱动程序嵌入的 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);
有没有办法使用 Driver 来控制 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屋!