Attach DOTM Template to Word File & Automatically Update Document Styles using Java

Hello there,

I’m trying to set style in the document using .dotm file as mentioned in the documentation.
But unable to generate expected output.
Please have a look in the following code and attached files.zip (68.1 KB)

and let me know if any solution is available for the same.

Document doc = new Document("input.docx");
doc.setAutomaticallyUpdateStyles(true);
doc.setAttachedTemplate("Normal.dotm");
doc.save("output.docx");

The expected output document should generate with the Arial font with size 10 as per the dotm file settings.

@nobilex,

In this case, Aspose.Words for Java mimics the behavior of MS Word. I have produced an output DOCX file (see ms word 2019.docx (15.9 KB)) by performing the following steps in MS Word 2019 and attached it here for your reference:

  • Open input.docx with MS Word 2019
  • Go to File | More | Options | Add-ins | Manage | Templates | Go
  • Under Templates tab, click Attach and specify the path to Normal.dotm
  • Tick mark the “Automatically update document styles” checkbox and click OK

I have also used the following Java code of Aspose.Words to produce this DOCX file (awjava-21.5.docx (11.6 KB)) which looks similar to what MS Word 2019 produces.

Document doc = new Document("C:\\Temp\\Files\\input.docx");
doc.setAttachedTemplate("C:\\Temp\\Files\\Normal.dotm");
doc.setAutomaticallyUpdateStyles(true);
doc.save("C:\\Temp\\Files\\awjava-21.5.docx");