Docx4j is an open source (ASLv2) Java library for creating and manipulating Microsoft Open XML (Word docx, Powerpoint pptx, and Excel xlsx) files. It is similar to Microsoft's OpenXML SDK, but for Java. docx4j uses JAXB to create the in-memory object representation.
If the templates will be used in Alfresco development to populate word documents, docx4j is a good choice. The fields in the template can be manipulated with your desktop application Microsoft Word. Then the templates can be saved to Alfresco. As we know, Alfresco is java based, which allows the Alfresco developers to merge the fields in the template and populate the data from database or repository.
Also, this availability could be embedded into workflow, so that users can input the parameters for the fields in the template. In certain later task, the template would be rendered into instance document.
Furthermore, the instance word document can be treated as a temporary result in memory, and then converted to PDF. Hence, the solution could be taken as a template to PDF. This is the replacement and enhancement of the PDF template, and it adds value to Alfresco.
Current community version (3.2.2) of Docx4j only supports property field MERGEFIELD, the enterprise version supports more function fields. Since docx4j is open source, it’s easy to get the source code of docx4j and work from it once custom fields and complex logic are needed.