Not able to add formatting to Page numbers


#1

Hi Team,

We have added page numbers to a word report using https://apireference.aspose.cloud/words/#!/PageNumbers/PostInsertPageNumbers api call. Can we add formatting like font-size, font-family, color etc to the page numbers added on the word.

Regards,
Nipun Jain


#3

@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.


#4

Hi Team,

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

Regards,
Nipun Jain


#5

@nipunjain1964

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


#6

@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!


#7

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


#8

Hi team,

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

Regards,
Nipun Jain


#10

@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!


#11

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


#12

@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!