Free Support Forum - aspose.cloud

How to add a header or footer to a word document using Aspose.Words REST API

Hi,
I’m trying to use the HeadersFooters Words Cloud API
/words/{name}/{sectionPath}/headersfooters

to add header and/or footer (plain text) and getting the errors. Can some give an example of what the complete HTTP request or set of requests should look like when you the HeadersFooters API ?

Thanks !

@kishores

Please follow these steps to add Header/Footer to Word document.

  1. Add Header/Footer to a document Section

​PUT/words​/{name}​/{sectionPath}​/headersfooters Inserts to document header or footer

The parameter values would be:

name = Header_doc.docx
sectionPath = sections/0
destFileName = Header_doc_output.docx
headerFooterType = “HeaderFirst” (Note the Double quotes)

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

  • HeaderEven
  • HeaderPrimary
  • HeaderFirst
  • FooterEven
  • FooterPrimary
  • FooterFirstcurl
  1. Add Text to a Header/Footer of a Section

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

The parameter values would be:

name = SampleDocument_Result.docx
paragraphPath = sections/0/headersfooters/0/paragraphs/0
run = { “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.

The parameter values would be:

name = SampleDocument_Result.docx
sectionIndex = 0
pageSetup = { “DifferentFirstPageHeaderFooter”: true }