2019-01-16 00:13:18 +00:00
|
|
|
# Page Numbers
|
|
|
|
|
|
|
|
> This feature allows you to set page numbers on each page
|
|
|
|
|
|
|
|
?> **Note:** This feature only works on Headers and Footers
|
|
|
|
|
|
|
|
```ts
|
2021-05-18 17:16:10 +03:00
|
|
|
new Paragraph({
|
|
|
|
children: [
|
|
|
|
new TextRun({
|
|
|
|
children: ["Page #: ", PageNumber.CURRENT],
|
|
|
|
})
|
|
|
|
]
|
|
|
|
})
|
2019-01-16 00:13:18 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
## Current page number
|
|
|
|
|
|
|
|
```ts
|
2021-05-18 17:16:10 +03:00
|
|
|
PageNumber.CURRENT
|
2019-01-16 00:13:18 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
For example:
|
|
|
|
|
|
|
|
```ts
|
2021-05-18 17:16:10 +03:00
|
|
|
new Paragraph({
|
|
|
|
children: [
|
|
|
|
new TextRun({
|
|
|
|
children: ["Page Number ", PageNumber.CURRENT],
|
|
|
|
})
|
|
|
|
]
|
|
|
|
})
|
2019-01-16 00:13:18 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
## Total number of pages
|
|
|
|
|
|
|
|
```ts
|
2021-05-18 17:16:10 +03:00
|
|
|
PageNumber.TOTAL_PAGES
|
2019-01-16 00:13:18 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
For example:
|
|
|
|
|
|
|
|
```ts
|
2021-05-18 17:16:10 +03:00
|
|
|
new Paragraph({
|
|
|
|
children: [
|
|
|
|
new TextRun({
|
|
|
|
children: ["Total Pages Number: ", PageNumber.TOTAL_PAGES],
|
|
|
|
})
|
|
|
|
]
|
|
|
|
})
|
2019-01-16 00:13:18 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
## Both
|
|
|
|
|
|
|
|
You can combine the two to get "Page 2 of 10" effect:
|
|
|
|
|
|
|
|
```ts
|
2021-05-18 17:16:10 +03:00
|
|
|
new Paragraph({
|
|
|
|
children: [
|
|
|
|
new TextRun("My awesome text here for my university dissertation. ")
|
|
|
|
new TextRun({
|
|
|
|
children: ["Page ", PageNumber.CURRENT, " of ", PageNumber.TOTAL_PAGES],
|
|
|
|
})
|
|
|
|
]
|
|
|
|
})
|
2019-01-16 00:13:18 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
### Simple Example
|
|
|
|
|
|
|
|
Adding page numbers to Header and Footer
|
|
|
|
|
2019-08-20 22:23:14 +01:00
|
|
|
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/39-page-numbers.ts ':include')
|
2019-01-16 00:13:18 +00:00
|
|
|
|
2019-08-20 22:23:14 +01:00
|
|
|
_Source: https://github.com/dolanmiu/docx/blob/master/demo/39-page-numbers.ts_
|