Format page numbers in Word Document Header and Footer with Aspose.Words REST API

Hi Team,

We have added page numbers to a word report using Aspose.Words Cloud - API References api call. Can we add formatting like font-size, font-family, color etc to the page numbers added on the word.

Regards,
Nipun Jain

@nipunjain1964

Yes, using Aspose.Words REST APIs, you can apply formatting such as Font-size, Font-family and Color to the Page Numbers added in the Word document.

But unfortunately, the API has a bug and we are trying to fix it (WORDSCLOUD-593). As soon as we are able to fix the issue, we will share with you a complete example to change the formatting of Page Numbers.

Hi Team,

We are about to go live with Aspose integration. Can you fix this bug asap.

Regards,
Nipun Jain

@nipunjain1964

We are actively working on this issue and we will update you here as soon as the issue is fixed.

@nipunjain1964

Please follow following steps to apply formatting like font-size, font-family and colour to Page Numbers added in a Word Document:

  1. Add Page Numbers in a Word document using the following API:
    POST /words/{name}/insertPageNumbers

Parameter values should be:
name = NewDocument.docx
pageNumber = { “Format”: “{PAGE}”, “Alignment”: “right”, “IsTop”: true, “SetPageNumberOnFirstPage”: true }
destFileName = NewDocument_PN.docx

Input Document: NewDocument.zip
Output Document: NewDocument_PN.docx.zip

  1. Then apply formatting to Page Numbers using the following API:
    POST /words/{name}/{paragraphPath}/runs/{index}/font

Parameter values will be:
name = NewDocument_PN.docx
fontDto = { “Bold”: true, “AllCaps”: true, “Color”: { “Web”: “#FF0000”, “Alpha”: 255 }, “Name”: “Arial”, “Size”: 14 }
paragraphPath = sections/0/headersfooters/1/paragraphs/0
index = 0

Output Document: NewDocument_PN.docx.zip

We hope this helps!

Hi Team,

Thanks for the response.

The font formatting works fine, if we have “Format”: “{PAGE}” in the InsertPageNumbers api call.

However, if we pass “Format”: “I am a Header Page {PAGE}” in the InsertPageNumbers api call, the api is not applying the formatting to the page number.

Please find the converted file attached herewith
sampledoc.zip (8.8 KB)

Regards,
Nipun Jain

Hi team,

We need to fix a live issue. Can you please look into this asap.

Regards,
Nipun Jain

@nipunjain1964

In order to apply font formatting to {PAGE} part of I am a Header Page {PAGE}, you need to update the run index.

For example, you can apply formatting to page numbers in sampledoc.docx document as follows:

API: POST /words/{name}/{paragraphPath}/runs/{index}/font

Parameter values:

name = sampledoc.docx
fontDto = { “Bold”: true, “AllCaps”: true, “Color”: { “Web”: “#FF0000”, “Alpha”: 255 }, “Name”: “Arial”, “Size”: 20 }
paragraphPath = sections/0/headersfooters/1/paragraphs/0
index = 1 (You need to update this value)

Output Document: sampledoc_Output.docx.zip

We hope this helps!

2 posts were split to a new topic: How to add multi line text in HeaderFooter of Word Document using Aspose.Words REST API