Page number not getting properly in HTML Output

Hello team,

I’m attempting to convert a Word document into HTML. However, before I perform this conversion, I am extracting each page one by one from the source document and appending them into a destination document. Then, I’m converting this new document to HTML. The problem is that in the HTML output, every page is displaying as “Page 1”. This is not matching the page numbering in the source document. How can I fix this issue?

Snippet :

string sourcePath = "D:\Source.docx";
Aspose.Words.Document sourceDoc = new Aspose.Words.Document(sourcePath);
Aspose.Words.Document destDoc = new Aspose.Words.Document();

for (int i = 0; i < sourceDoc.PageCount; i++)
{
    Document page = sourceDoc.ExtractPages(i, 1);
	destDoc.AppendDocument(page, ImportFormatMode.KeepSourceFormatting);
}
 destDoc.Save(@"D:\Output.html");

Attachments:
WordToHTML_Issue.zip (378.2 KB)

@AlpeshChaudhariDev You should unlink PAGE field to get the desired result:

Document sourceDoc = new Document(@"C:\Temp\in.docx");
Document destDoc = new Document();

for (int i = 0; i < sourceDoc.PageCount; i++)
{
    Document page = sourceDoc.ExtractPages(i, 1);
    // unlink page field
    page.Range.Fields.Where(f => f.Type == FieldType.FieldPage).ToList()
        .ForEach(f => { f.Update(); f.Unlink(); });

    destDoc.AppendDocument(page, ImportFormatMode.KeepSourceFormatting);
}
destDoc.Save(@"C:\Temp\out.html");
1 Like

@alexey.noskov It’s working well now. Thanks for your quick response.

1 Like