Please supply code in Visual Basic, not C#.
As I mentioned in my original message, my program just reads a document, calls UpdateFields and UpdatePageLayout, then saves the result.
Thanks for the additional information. While using latest Aspose.Words 11.1.0. I managed to reproduce this problem on my side. I have logged your issue as WORDSNET-6007 into our bug tracking system. Your request has also been linked to the appropriate issue. Once we sort it out, we will let you know. Sorry for inconvenience.
Hello Mark and all Aspose Team Respondents,
I have posted a forum request of a similar nature, my code is in C#. I'm going to make a leap of faith here and say I just may have solved the problem. :) You all will be relieved to know there may not be a bug after all!
What finally solved this issue, now that it is perfectly obvious is to call the TOC within the manually coded AppendDocument() method. It could be the direct .AppendDocument() may not be working as it should.
Here is our original code. The TOC methods were being called prior to ReportAssembly(). The solution of applying these methods after was attempted, it did not work. The page numbers were always off.
//docGenerated.UpdateFields();//Updates the TOC.
//docGenerated.UpdatePageLayout(); //Puts the page numbers into the TOC
Within ReportAssembly(), AppendDocument() is called:
AppendDocument(docTemplateTitlePage, docGenerated, ImportFormatMode.KeepSourceFormatting);
The TOC methods were placed in the manually coded AppendDocument() with signature as below. (as opposed to using the document.AppendDocument(Document sourceDoc, ImportFormatMode mode) method)
public void AppendDocument(Document templDoc, Document genDoc, ImportFormatMode mode)
foreach (Section srcSection in genDoc)
Node dstSection = templDoc.ImportNode(srcSection, true, mode);
templDoc.UpdateFields();//Updates the TOC.
templDoc.UpdatePageLayout(); //Puts the page numbers into the TOC
Bingo, problem solved.
If others are not using AppendDocument(), this obviously won't be a solution. But this works perfectly for us on this end. Perhaps a solution for all might be to create a new document in this method, append each section of the imported document into it, do the TOC updates?
At any rate, this solved my issue.
I don’t think Mike’s suggestion helps me. I am already calling Document.UpdateFields and Document.UpdatePageLayout, as I mentioned in
https://forum.aspose.com/t/63436. The problem occurs even when I don’t append documents together. I would have expected calling UpdateFields and UpdatePageLayout would generate the same page numbers as selecting the entire document in Word and pressing F9 to update the fields. Unfortunately it appears that the 2 methods sometimes yield different results. Word shows the correct page numbers in this case, but Aspose.Words does not.
Thank you for additional information. It is perfect that you managed work the problem around. The problems with pagination might occur if your document has some content that Aspose.Words does not support or not fully support upon building document layout. For example: Floating tables and shapes, frames, MathML formulas.
It looks like the problem might be because in Word 2007 under Word Options->Advanced, Compatibility Options it says to lay out this document as if created in Custom. Normally it says “Microsoft Office Word 2003” for the documents I’m handling. Maybe the problem occurs because some odd custom settings are not handled by Aspose.Words.