Add Footer text and page number to all pages

Hi Guys,

I felt the documentation regarding header and footer a little superficial, specially on the body content.

Can anyone help me on how to add a text as footer and page number to all pages using REST API?

Thanks!

@gbastian

You can add Header/Footer to Word document using following steps:

  1. Add Header/Footer to a document Section
    ​PUT/words​/{name}​/{sectionPath}​/headersfooters Inserts to document header or footer

The possible values of header/footer type request body are:

  • HeaderEven
  • HeaderPrimary
  • HeaderFirst
  • FooterEven
  • FooterPrimary
  • FooterFirst
curl -X PUT "https://api.aspose.cloud/v4.0/words/AsposeThreeD.docx/sections%2F0/headersfooters?folder=Temp" 
-H "accept: application/json" 
-H "Authorization: Bearer [Access_Token]" 
-H "Content-Type: application/json" 
-H "x-aspose-client: Containerize.Swagger" 
-d "\"HeaderFirst\""
  1. Add Text to a Header/Footer of a Section

POST ​/words​/{name}​/{paragraphPath}​/runs Adds run to document, returns added paragraph’s data.

curl -X POST "https://api.aspose.cloud/v4.0/words/AsposeThreeD.docx/sections%2F0%2Fheadersfooters%2F0%2Fparagraphs%2F0/runs?folder=Temp" 
-H "accept: application/json" 
-H "Authorization: Bearer [Access_Token]" 
-H "Content-Type: application/json" 
-H "x-aspose-client: Containerize.Swagger" 
-d "{"Text":"Aspose.Words Cloud"}"
  1. Update Section Setup

Now finally set DifferentFirstPageHeaderFooter value using following API as per your scenario.

PUT ​/words​/{name}​/sections​/{sectionIndex}​/pageSetup Updates page setup of section.

@gbastian

Please use the following API to add Page number in the Word document. It will add page numbers in the footer as per the section page setup. The Request body value can use {PAGE} and {NUMPAGES} fields.

{PAGE}
or
{PAGE} of {NUMPAGES}

PUT ​/words​/{name}​/PageNumbers Inserts document page numbers.

@tilal.ahmad, tks.

I´m still getting an error. What is wrong with this body request?

{
“HeaderFooter”: {
“link”: {
“Type”: “FooterFirst”,
“Text”: “Aspose.Words Cloud”
}
}
}

@gbastian

You already passed the header/footer index in paragraphpath parameter, so now only you need to pass the Text like

{
“Text”: “Aspose.Words Cloud”
}