I'm currently deploying docx4j library to generate MS-Word and PDF documents from a .dotx document created with MS Office. Now I'm facing an issue that it loses all style formattings inside the paragraph if it contains "MERGEFIELD" placeholder.
The following is the sample dotx file before processing with MailMerger class:
<w:p w:rsidR="00FD281F" w:rsidRPr="00681127" w:rsidRDefault="00A26E2F" w:rsidP="002379F5">
<w:pPr>
<w:jc w:val="center" />
</w:pPr>
<w:r w:rsidRPr="00681127">
<w:t xml:space="preserve">No: </w:t>
</w:r>
<w:fldSimple w:instr=" MERGEFIELD No \* MERGEFORMAT ">
<w:r w:rsidR="00E111B1">
<w:rPr>
<w:noProof />
</w:rPr>
<w:t>test</w:t>
</w:r>
</w:fldSimple>
</w:p>
And the following is the generated docx file:
<w:p w:rsidR="00FD281F" w:rsidRPr="00681127" w:rsidRDefault="00A26E2F" w:rsidP="002379F5">
<w:pPr>
<w:noProof />
</w:pPr>
<w:r w:rsidRPr="00681127">
<w:t xml:space="preserve">No: </w:t>
</w:r>
<w:r>
<w:rPr>
<w:noProof />
</w:rPr>
<w:t>KZ-2013-1018</w:t>
</w:r>
</w:p>
Note that "<w:pPr><w:jc w:val="center" /></w:pPr>" is replaced with <w:pPr><w:noProof /></w:pPr>". Thus the formatting style for centering is lost.
The version of docx4j is 2.8.1.
Does anyone know why this happens and how to keep the original formatting styles?