Files
docx/docs/usage/page-numbers.md
T
Dolan 3539c06e92 docs: Improve inline docs and docs website (#3353)
* docs: Improve inline docs and docs website

* Fix lint

* Fix spelling
2026-02-14 03:54:25 +00:00

1.3 KiB

Page Numbers

This feature allows you to set page numbers on each page

?> Note: This feature only works on Headers and Footers

new Paragraph({
    children: [
        new TextRun({
            children: ["Page #: ", PageNumber.CURRENT],
        }),
    ],
});

Current page number

PageNumber.CURRENT;

For example:

new Paragraph({
    children: [
        new TextRun({
            children: ["Page Number ", PageNumber.CURRENT],
        }),
    ],
});

Total number of pages

PageNumber.TOTAL_PAGES;

For example:

new Paragraph({
    children: [
        new TextRun({
            children: ["Total Pages Number: ", PageNumber.TOTAL_PAGES],
        }),
    ],
});

Both

You can combine the two to get "Page 2 of 10" effect:

new Paragraph({
    children: [
        new TextRun("My awesome text here for my university dissertation. ")
        new TextRun({
            children: ["Page ", PageNumber.CURRENT, " of ", PageNumber.TOTAL_PAGES],
        })
    ]
})

Examples

Simple Example

Adding page numbers to Header and Footer

Example

Source: https://github.com/dolanmiu/docx/blob/master/demo/39-page-numbers.ts