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

Free Support Forum - aspose.com

Track Page No, Line No, Header and Footer Revisions in a word document

We have 30 to 40 revisions in a word document which need to track the PageNo , LineNo , Header Text and Footer Text

Ex: 1st page contains 3 revisions and 4th page contains 5 revisions.
Expected Output: For 1st Revision in 1st page
Change Type: Insertion
Text: ABCDEF
PageNo: 1
Line No : 5
Header Text Changed: Summary to Summarize
Footer Text Changed: All Rights to All Rights Reserved

For 2nd Revision in 1st page
Change Type: Insertion
Text: GHIJKLM
PageNo: 1
Line No : 10
Header Text Changed: Summary to Summarize
Footer Text Changed: All Rights to All Rights Reserved
etc etc

How we can achieve this? Please provide a solution.
Thanks in advance.

@sureshkap
You can output all of this information except of LineNo.

Document doc = new Document("TestDoc.docx");
int pageCount = doc.PageCount;
for (int i = 0; i < pageCount; i++)
{
    Document pagedDoc = doc.ExtractPages(i, 1);
    foreach (Revision rev in pagedDoc.Revisions)
    {
        if (rev.ParentNode.NodeType != NodeType.Run)
            continue;
        string text = (rev.ParentNode as Run).Text;
        Console.WriteLine("Change Type: " + rev.RevisionType.ToString());
        Console.WriteLine("Text: " + text);
        Console.WriteLine("PageNo: {0}", i + 1);
        PageSetup ps = pagedDoc.FirstSection.PageSetup;
        string headerText = pagedDoc.FirstSection.HeadersFooters[HeaderFooterType.HeaderPrimary].GetText().Trim();
        string footerText = pagedDoc.FirstSection.HeadersFooters[HeaderFooterType.FooterPrimary].GetText().Trim();
        if (ps.DifferentFirstPageHeaderFooter && (i == 0))
        {
            headerText = pagedDoc.FirstSection.HeadersFooters[HeaderFooterType.HeaderFirst].GetText().Trim();
            footerText = pagedDoc.FirstSection.HeadersFooters[HeaderFooterType.FooterFirst].GetText().Trim();
        }
        if (ps.RestartPageNumbering && (ps.PageStartingNumber % 2 == 0))
        {
            headerText = pagedDoc.FirstSection.HeadersFooters[HeaderFooterType.HeaderEven].GetText().Trim();
            footerText = pagedDoc.FirstSection.HeadersFooters[HeaderFooterType.FooterEven].GetText().Trim();
        }

        Console.WriteLine("Header Text Changed: " + headerText);
        Console.WriteLine("Footer Text Changed: " + footerText);
        Console.WriteLine();
    }
}

TestDoc.docx (19.6 KB)

Thank You for your quick response.
Extractpages method does not exist. Is it something changed in any of the version. As of now we are using Aspose.Words- 20.8.0 version

@sureshkap You can upgrade to the latest version of Aspose.Words or use LayoutCollector.GetStartPageIndex(rev.ParentNode) instead of ExtractPages to detect the page number.

LayoutCollector collector = new LayoutCollector(doc);

foreach (Revision rev in doc.Revisions)
{
    if (rev.ParentNode.NodeType != NodeType.Run)
        continue;
    string text = (rev.ParentNode as Run).Text;
    Console.WriteLine("Change Type: " + rev.RevisionType.ToString());
    Console.WriteLine("Text: " + text);
    int pageNum = collector.GetStartPageIndex(rev.ParentNode);
    Console.WriteLine("PageNo: {0}", pageNum);
    PageSetup ps = doc.FirstSection.PageSetup;
    string headerText = doc.FirstSection.HeadersFooters[HeaderFooterType.HeaderPrimary].GetText().Trim();
    string footerText = doc.FirstSection.HeadersFooters[HeaderFooterType.FooterPrimary].GetText().Trim();
    if (ps.DifferentFirstPageHeaderFooter && (pageNum == 1))
    {
        headerText = doc.FirstSection.HeadersFooters[HeaderFooterType.HeaderFirst].GetText().Trim();
        footerText = doc.FirstSection.HeadersFooters[HeaderFooterType.FooterFirst].GetText().Trim();
    }
    if (pageNum % 2 == 0)
    {
        headerText = doc.FirstSection.HeadersFooters[HeaderFooterType.HeaderEven].GetText().Trim();
        footerText = doc.FirstSection.HeadersFooters[HeaderFooterType.FooterEven].GetText().Trim();
    }

    Console.WriteLine("Header Text Changed: " + headerText);
    Console.WriteLine("Footer Text Changed: " + footerText);
    Console.WriteLine();
}