We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

TOC not updated on save


we are currently testing outputting a document composed of many merged template

  • cover
  • TOC
  • document 1
  • document N

The documents from 1 to N then use the styles which are used by the TOC to build itself; the final document is about 400 pages long.

Before saving the document to disk, it is “cleaned up” like this:


However, even explicitely calling updateFields() before save() seems to have no effect on the TOC.

How do I get the TOC to be correctly updated when the document is first opened? This is especially an issue if the document is saved as PDF, because then no fields can be manually updated anymore.


Thanks for your inquiry. To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document.
  • Please attach the output Word file that shows the undesired behavior.
  • Please create a simple Java application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we’ll start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.

Considering that the final document is made of ~110 single templates, I really cannot provide you with a “simple Java application” to show the issue.

Upon further tests, I noticed that this is caused by the code you gave me here: https://forum.aspose.com/t/re-how-to-remove-blank-pages-in-word-files-before-appending-them/57664/24

As soon as I remove that trimming code, the TOC is correct again, so I guess it is being trimmed out.


the culprit seems to be in the block

if(doc.getLastSection().getBody().getLastParagraph().getChildNodes(NodeType.SHAPE, true).getCount() > 0
            || doc.getLastSection().getBody().getLastParagraph().getChildNodes(NodeType.GROUP_SHAPE, true).getCount() > 0
            || doc.getLastSection().getBody().getLastParagraph().getChildNodes(NodeType.FORM_FIELD, true).getCount() > 0
            || doc.getLastSection().getBody().getLastParagraph().getChildNodes(NodeType.FOOTNOTE, true).getCount() > 0
            || doc.getLastSection().getBody().getLastParagraph().getChildNodes(NodeType.COMMENT, true).getCount() > 0

It would seem your “generic” solution missed out something not to be trimmed, but I would not know which NodeType it is.


Thanks for your inquiry. Please comment the trimming code, generate the output document and share it here for testing. We will investigate the issue on our side and provide you more information.