namespace AddPageNumbersInWordUsingCSharp
{
    class Program
    {
        static void Main(string[] args) // Main function to Add Page Numbers in Word using C#
        {
            // Load the license to avoid a watermark in the output Word file
            // after adding the page numbers in the footer
            Aspose.Words.License licAddPageNumber = new Aspose.Words.License();
            licAddPageNumber.SetLicense("Aspose.Word.lic");

            // Load the input Word file for adding page numbers
            Aspose.Words.Document wordFile = new Aspose.Words.Document("word.docx");

            // Instantiate the DocumentBuilder object to move around and insert contents
            Aspose.Words.DocumentBuilder fileBuilder = new Aspose.Words.DocumentBuilder(wordFile);

            // Using the builder, move to the primary footer section
            fileBuilder.MoveToHeaderFooter(Aspose.Words.HeaderFooterType.FooterPrimary);

            // Add the page number field along with the condition using IF
            Aspose.Words.Fields.Field field = fileBuilder.InsertField("IF ", null);
            fileBuilder.MoveTo(field.Start.NextSibling.NextSibling);

            // Insert the field in to the moved location i.e. footer
            fileBuilder.InsertField(Aspose.Words.Fields.FieldType.FieldPage, false);

            // add the IF expression to be checked before inserting page number
            fileBuilder.Write(" > 4 \"");

            // In the TRUE segment of the IF condition add another field
            fileBuilder.InsertField(Aspose.Words.Fields.FieldType.FieldPage, false);

            // In the FALSE part of the IF condition insert blank string
            fileBuilder.Write("\" \"\"");

            // Move to the start of the document for adding blank pages
            fileBuilder.MoveToDocumentStart();

            // Insert a defined number of blank pages
            for (int page = 0; page < 15; page++)
                fileBuilder.InsertBreak(Aspose.Words.BreakType.PageBreak);

            // Save to output Word file with page number in the DOCX format
            wordFile.Save("show hide page numbers .docx");

            System.Console.WriteLine("Done");
        }    
    }
}