I'm currently trying to update the table of contents in a document so that the page numbers are updated. The table of contents are initially part of a document that is being merged with other documents.
Once all the documents are merged together, I call the update table of contents method.
However, once I generate the final document, the table of contents has been replaced by the string "TOC".
I've tried looking for an answer as to what is happening but haven't had any luck.
We have tried to reproduce the reported problem using the given details, but it works properly at our end. For your reference, we have attached the sample application which we tried to reproduce the reported problem at our end, and it can be downloaded from the below attachment.
Note: Please find the input Word document in the “Data” folder of the attached sample application.
Could you please try the attached sample application at your end and provide us confirmation whether you are facing issues in this sample.
If the issue is not reproduced using the attached sample application at your end, then could you please modify the attached sample as an issue reproducible sample application and share us. Thereby, we will proceed further to replicate the same problem at our end and will provide you appropriate solution at the earliest.
I've been doing some research alongside your example (which works fine on my end).
The issue appears to be stemming from the page numbers in the footers of my .docx files.
I removed them and the Table of Contents updates correctly.
I'm going to be doing more testing today and will update this post when I have a solution.
This issue is now resolved.
The solution was to ensure that page numbers are formatted correctly within a document.
In my case, I imported all documents together and then wrote the footer myself programmatically, including page numbers.
I then updated the table of contents and everything worked fine.