Insert Page Number Issue


Dear Team,

We have problem with insert page number in document. i have attached documents Please find and give as solution.
Note: Some Files Only Not Working Properly

Input File (955.9 KB)

Source Code (1.1 KB)

Thank you in Advance



We have tested the scenario and have not found any issue. Could you please share the issue that you are facing while inserting the Page field? We will then provide you more information about your query.


@tahir.manzoor and team,

No, I face same issue now also, Again i shared a input and out file to u,

issue scenario
some file page numbers field are not insert properly
input file (955.9 KB)

output file (918.9 KB)

Screen Shot
i attached 3 page screen shot but the issue is same in all pages
Aspose Issue_screen (485.6 KB)



As per our understanding, you want to insert page number at the start of each page. We suggest you please move the cursor to the header of document using DocumentBuilder.MoveToHeaderFooter method and insert the page field.

If this does not help you, please manually create your expected Word document using Microsoft Word and attach it here for our reference. We will investigate how you want your final Word output be generated like. We will then provide you more information on this along with code.


@tahir.manzoor and Team,
I try to use “DocumentBuilder.MoveToHeaderFooter method and insert the page field.” but I am not getting expected output :disappointed:
I attached expected, actual output and input file (2.7 MB)



Please use the following code example to insert the page number field in the header of document. Hope this helps you.

Document inputdoc = new Document(MyDir + "input.docm");
DocumentBuilder builder = new DocumentBuilder(inputdoc);
builder.write("[Page ");
builder.insertField(FieldType.FIELD_PAGE, false);
builder.write("] ");

builder.write("[Page ");
builder.insertField(FieldType.FIELD_PAGE, false);
builder.write("] ");

builder.write("[Page ");
builder.insertField(FieldType.FIELD_PAGE, false);
builder.write("] ");

inputdoc.removeMacros(); + "output.docx");

If you still want to insert the page number field in the page’s body, you need to register the hyphenation dictionary as shown below. After registering the English dictionary, the page layout will be correct and you can get the correct Run/Paragraph node at the start of page.

Hyphenation.registerDictionary("en-US", MyDir + "hyph_en_US.dic");
Document inputdoc = new Document(MyDir + "input.docm");


@tahir.manzoor and team,

Hyphenation.registerDictionary(“en-US”, MyDir + “hyph_en_US.dic”);
Document inputdoc = new Document(MyDir + “input.docm”);

Above code working fine but some files also face the same issue.
I attached Screen Shots for the issue pages
Issue (393.3 KB)
Note: Expected output already sent before (Insert Page Number Issue)

Thank you in advance



We are investigating this issue and will get back to you soon.



In your case, the layout API does not get the correct text (Run node) at the start of page. So, you get the incorrect position of page field. We have logged this problem in our issue tracking system as WORDSNET-18825. You will be notified via this forum thread once this issue is resolved. We apologize for your inconvenience.

After the fix of this issue, you can use the same code to insert the page field.


Dear @tahir.manzoor and Team,
This is very Urgent Requirement kindly do the needful.
Thank you in advance



We try our best to deal with every customer request in a timely fashion, we unfortunately cannot guarantee a delivery date to every customer issue. We work on issues on a first come, first served basis. We feel this is the fairest and most appropriate way to satisfy the needs of the majority of our customers.

Currently, your issue is pending for analysis and is in the queue. Once we complete the analysis of your issue, we will then be able to provide you an estimate.



Thanks for your patience. It is to inform you that the issue which you are facing is actually not a bug in Aspose.Words. So, we have closed this issue (WORDSNET-18825) as ‘Not a Bug’.

Your problem in the document is related to hyphenation dictionary. You should perform following change in the hyph_en_US.dic:

  • Add next patterns to the bottom of the hyph_en_US.dic: