FOP:java xml - > pdf转换比从控制台慢6倍

时间:2017-02-03 09:43:52

标签: java xml pdf xslt apache-fop

我正在使用Apache FOP从xml生成带有xsl:fo xsl样式表的PDF文件。 传入XML(存储在StringWriter中)大约为266000-300000行。结果PDF约250-300页。

Java在大约30-35秒内生成相同的文件。如果我只使用控制台,则会在大约5-6秒内生成相同的文件。

以下是处理XML和XSL的Java代码的摘录:FO并生成PDF。

Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, outPutStream);
TransformerFactory transformerFactory = new net.sf.saxon.TransformerFactoryImpl();
Transformer transformer = transformerFactory.newTransformer(new StreamSource(xsltFile));

transformer.setParameter("versionParam", "2.0");
transformer.setParameter("interval", messagingService.getReportInterval());    
transformer.setParameter("clientId", messagingService.getReportClientId());
transformer.setParameter("clientName",messagingService.getReportClientName());
transformer.setParameter("transactionTime", messagingService.getReportTransactionTime());
transformer.setParameter("transactionReceipt", messagingService.getReportReceipt());
transformer.setParameter("bruttoAmount", messagingService.getReportBruttoSum());
transformer.setParameter("feeAmount", messagingService.getReportFee());
transformer.setParameter("nettoAmount", messagingService.getReportNettoSum());
transformer.setParameter("currency", messagingService.getReportCurrency());
transformer.setParameter("total", messagingService.getReportTotal());

Source source = new StreamSource(new StringReader(xmlSource.toString()));
Result result = new SAXResult(fop.getDefaultHandler());
transformer.transform(source, result);

也许我做错了什么或者有提高性能的技巧?

0 个答案:

没有答案