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

Free Support Forum - aspose.com

Adding header footer to .docx file

Dear Support,

I want to control the appearance of header and footer as follows.

  1. Appear header in first page and footer in last page
  2. Appear header and footer in all pages.
  3. combination of the two

Can we achieve It?


We have PAGE field and NUMPAGES field. PAGE field represents number of current page while NUMPAGES represents the total number of pages in document. You can make use of IF field in header/footer to detect first and last pages. For example,

You can show header in first page and footer in last page like this:

{ IF “{PAGE}” = “1” “Header Content” “” }


{ IF “{PAGE}” = “{NUMPAGES}” “Footer Content” “” }

Hope, this helps.

Dear Awais hafeez,
This solution will not work for document having literally no section break and running across multi pages while editing/adding paragraphs?

Please share some sample code if that works.


Please ZIP and attach your input Word document, Aspose.Words generated output document (if any) and expected document showing the final output here for our reference. You can create expected document by using MS Word. We will investigate the issue further on our end and will provide you more information.