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

Free Support Forum - aspose.com

Update Entire Table of Contents & Retain Page Numbers of TOC Field during Converting DOCX to PDF using C# .NET

When loading in a DOCX with incorrect page numbers in the TOC, saving the document to DOCX and PDF results in incorrect page numbers in the TOC. The SaveOptions in the documentation say that UpdateFields is true by default, but I get a different result if it is called manually. If I manually add a call to UpdateFields after loading in the document, then the PDF comes out correct and the DOCX changes but is still wrong. I also tried passing in SaveOptions with UpdateFields set to true and that did the same as not providing SaveOptions. I tried this on Aspose.Words for .NET version 19.11 and 20.4. I got the same results from both.

While some of the earlier sections are wrong, such as 2.4.1, the easiest section to look at is the last section as it is the most off.

I used the following code and these are my input/output files: IncorrectPageNumbers2.zip (638.4 KB)

Document test = new Document("Incorrect_PageNumbers.DOCX");
test.Save("Incorrect_Aspose.DOCX");
test.Save("Incorrect_Aspose.PDF");

Document test2 = new Document("Incorrect_PageNumbers.DOCX");
test2.UpdateFields();
test2.Save("Incorrect_Aspose2.DOCX");
test2.Save("Correct_Aspose.PDF");

@bmentzer,

We have logged this problem in our issue tracking system. Your ticket number is WORDSNET-20363. We will further look into the details of this problem and will keep you updated on the status of the linked issue. Sorry for the inconvenience.