Page numbers problem

Hi,

I’m using Aspose.Words version 18.7.0 to create one document with AppendDocument API but page numbers are not updated properly.
I’ve added codes described in the link below to remove section breaks and page breaks too but still not working.

here is the code :

//
public List Merge(List generatedDocuments)
{
if (generatedDocuments.Count < 2)
{
return generatedDocuments;
}

        // Get the first document as the main document
        var mergedDocument = generatedDocuments.First();

        // Merge all the following documents
        for (var i = 1; i < generatedDocuments.Count; i++)
        {
            var associatedDocument = generatedDocuments[i];
            RemovePageBreaks(associatedDocument);
            RemoveSectionBreaks(associatedDocument);
            associatedDocument.FirstSection.PageSetup.SectionStart = SectionStart.Continuous;

            mergedDocument.AppendDocument(associatedDocument, ImportFormatMode.KeepSourceFormatting);
        }

       
        return new List<AsposeDocument> { mergedDocument };
    } 

after calling above code I call the following APIs to update TOC etc.

document.UpdateFields();
document.UpdatePageLayout();
document.UpdateListLabels();
document.UpdateTableLayout();
document.UpdateWordCount();

What else should I do for the page numbers to get get updated properly?
Thanks

@Mo2,

Thanks for your inquiry. To ensure a timely and accurate response, please ZIP and attach the following resources here for testing:

  • Your input Word document(s)
  • Aspose.Words generated output DOCX file showing the undesired behavior
  • Your expected DOCX Word document. We will investigate the structure of your expected document as to how you want your final output be generated like. You can create expected document by using Microsoft Word. Please also list the complete steps that you performed in MS Word to get the desired output
  • Please also create a standalone console application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing. Please do not include Aspose.Words.dll files in it to reduce the file size.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you code to achieve the same by using Aspose.Words. Thanks for your cooperation.

Thanks!

I’ve created the simplest example that I could.
If you open the input word document you see pages with correct page numbers.
After running the code and generating pdf document, the last page show page (4 of 3) which is wrong. We want to understand what is the problem?

DocumentApp1.zip (95.1 KB)

Result.pdf (67.2 KB)

input.zip (27.5 KB)

@Mo2,

The problem occurs because you are using Aspose.Words in evaluation mode (without applying license). We managed to reproduce the same issue (see 18.8-eval.pdf (69.2 KB)) when using the following code:

Document doc = new Document("D:\\Temp\\Doc1.docx");
doc.Save("D:\\temp\\18.8-eval.pdf");

However, the following code produces the correct output (see 18.8.pdf (46.1 KB))

Aspose.Words.License license = new Aspose.Words.License();
license.SetLicense("D:\\Temp\\Aspose.Words.lic");
Document doc = new Document("D:\\Temp\\Doc1.docx");
doc.Save("D:\\temp\\18.8.pdf");

The problem happen when the document grows during generation. For example I added a table of content and When I call UpdateFields it gets updated and makes document grow and wrong page numbers get generated.Here I’ve used a proper license.We want to understand why?

input.zip (29.1 KB)
Result.pdf (63.2 KB)

@Mo2,

This is not an issue with Aspose.Words. If you update TOC by using Aspose.Words or MS Word 2016, the content vertically grows and some content is pushed to fourth page. To identify the problem, please check this screenshot. Please use NUMPAGES field inside document’s footer. Hope, this helps.