Our use case is to generate a word doc from HTML’s and also to include a few more information such as header, footer & TOC using IReplacingCallBack implementation. We are using Aspose.Words 21.7 version with valid license in environments.
The inserted TOC fields generate entries using heading levels with incorrect page numbers in a few cases on certain page and cascades to the rest of the pages following. See Incorrect Page Number in TOC.png (16.1 KB) for example.
We do ensure to call all the below listed Api’s to get the page numbers right, but they all didn’t help. But manually updating TOC in the Word app refreshes and corrects the right page numbers.
- doc.UpdateFields() & doc.UpdatePageLayout() in this order
- fieldToc.UpdatePageNumbers() &
Attaching the sample project and generated document which mimics our exact problem for your perusal. Please do confirm us if we are missing any to get it right or it is something your team can help with a fix.
Sampe doc which has issue.docx (39.4 KB)
Sample App.7z (3.0 KB)