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
- Create a new word document with three lines of random text.
- Set a style of Heading 1 on the first, Heading 2 on the second, and heading 3 on the third.
- Add a ToC at the beginning of the document. It can all be on page one.
- Save the document.
- 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!