How to add multi line text in HeaderFooter of Word Document using Aspose.Words REST API

Hi Team,

Thanks for the response.

We are having header / footer text in multiple lines. How can we achieve that using [POST /words/{name}/insertPageNumbers] call.

An example of header text is “We are tesing headers\n\nWe are tesing headers\n\nWe are tesing headers”.

We are getting only the first line in header text “We are tesing headers”, if we pass “We are tesing headers\n\nWe are tesing headers\n\nWe are tesing headers” as “Format” to Post insertPageNumbers api call.

We have tried multiple options \n, \r\n and
for line breaks, but nothing is working.

Regards,
Nipun Jain

@nipunjain1964

With Aspose.Words REST APIs, you can add a multi-line text in a header/footer of a document. Following are the steps to add a multi-line header:

1- Add header with PUT method (it will create one empty paragraph). The parameters values would be:
name = NewDocument.docx
headerFooterType = “HeaderFirst” (Note the Double quotes)
destFileName = NewDocument_N.docx

2- Add text to the paragraph:

PUT /words/{name}/{paragraphPath}/runs
The parameters values would be:

name = NewDocument_N.docx
paragraphPath = sections/0/headersfooters/0/paragraphs/0
run = { “Text”: “First Line Header!” }

3- Finally set DifferentFirstPageHeaderFooter value to true using following API:
POST /words/{name}/sections/{sectionIndex}/pageSetup . The parameters values would be:

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

Input Document: NewDocument 2.zip
Output Document: NewDocument_N.docx.zip

Now for adding each new line (of header text), add a new paragraph to the document’s header using the following API:

PUT /words/{name}/{nodePath}/paragraphs

The parameters values would be:
name = NewDocument_N.docx
paragraph = { “Text”: “Second Line Header” }
nodePath = sections/0/headersfooters/0

Output Document: NewDocument_NN.docx.zip

Similarly, you can add another line (of header text) by again calling PUT /words/{name}/{nodePath}/paragraphs API.

name = NewDocument_N.docx
paragraph = { “Text”: “Third Line Header” }
nodePath = sections/0/headersfooters/0

Output Document: NewDocument_NNN.docx.zip

We hope this helps!