The UpdateFields command recreates bookmarks used in the ToC

It seems that the call to UpdateFields() is recreating the hidden bookmarks used to process the Table of Contents (ToC) in a document. It does not delete the now-unused bookmarks that were previously there, but just adds new bookmarks. The problem is that as you get more and more bookmarks in the documents, the UpdateFields command takes longer to execute. Some documents have many thousands of bookmarks ( over 100,000 bookmarks) and takes over a minute to process on the server. Removing the hidden bookmarks seems to resolve the issue.

Steps to reproduce

  1. Create a new word document with three lines of random text.
  2. Set a style of Heading 1 on the first, Heading 2 on the second, and heading 3 on the third.
  3. Add a ToC at the beginning of the document. It can all be on page one.
  4. Save the document.
  5. Process the document in Aspose as follows
Document doc = new Document("theFileYouJustSaved");
int nBookmarksBefore = doc.Range.Bookmarks.Count;
int nBookmarksAfter = doc.Range.Bookmarks.Count;

If you compare nBookmarksBefore and nBookmarks after, you see that there are four more bookmarks after. This is one for the ToC and three for the lines of text. If you run doc.UpdateFields() multiple times, in this scenario, on the next check, the bookmark count will have increased by a multiple of four.

We update our documents using UpdateFields and then save those changes back into our database. So, over time, we are creating a time bomb (excuse the pun) for ourselves, depending on the content of our customers’ documents.

Please advise, and have a nice day!


We are working on your query and will get back to you soon.


We tested the scenario and have managed to reproduce the same problem on our end. For the sake of correction, we have logged this problem in our issue tracking system. The ID of this issue is WORDSNET-17663. We will further look into the details of this problem and will keep you updated on the status of correction. We apologize for your inconvenience.

The issues you have found earlier (filed as WORDSNET-17663) have been fixed in this Aspose.Words for .NET 18.12 update and this Aspose.Words for Java 18.12 update.