Optimize docx4j performance

♀尐吖头ヾ 提交于 2019-12-11 20:13:37

问题


I am using docx4j 2.8.1 to replace texts and a logo within the word files. Now I want to improve performance since the processing of about 50 documents is quite slow. What options are recommended to increase performance of docx4j?

The code to replace the strings (not the logo) looks like:

 String xml = XmlUtils.marshaltoString(documentPart.getJaxbElement(), true);
 HashMap<String, String> mappings = buildReplaceMap(userData);

 Object obj = XmlUtils.unmarshallFromTemplate(xml, mappings);
 documentPart.setJaxbElement(obj);

回答1:


Please try http://www.docx4java.org/docx4j/docx4j-nightly-20130328.jar

It contains an experimental variableReplace method. Assuming documentPart and mappings as per your question, you can call:

documentPart.variableReplace(mappings);

You don't need documentPart.setJaxbElement.

In my testing with a 175 page document, processing took 1/3 sec (roughly 3 times faster).

Any further performance improvements will come most easily from providing more resources (more cores, if you want to do it concurrently), and more RAM.

Let me know what you think.



来源:https://stackoverflow.com/questions/15664726/optimize-docx4j-performance

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