Text

Page Numbers

Quickly insert fields for page numbers.

The following methods allow you to insert page numbers within a paragraph:

MethodDescription
CurrentPageNumber()Appends a field formulated to show the current page number.
TotalPages()Appends a field formulated to show the total number of pages in the document.
Field values (in this case page numbers) are not computed by the library; this is done by word processors. FluentWriter defines the initial value of fields as the field formula surrounded by braces. For example, the display value for the current page in a document is { PAGE \* MERGEFORMAT } until computed. Word processors such as Microsoft Word will typically compute page numbers in headers and footers when a document is opened.

For example, the following code displays page numbers within a footer:

using FluentWriter;
using FluentWriter.Common;

WordDocument.Create(savePath, document =>
{
    document.Section(section =>
    {
        section.PageSize(PageSizes.Letter);
        section.Content(() => {/* Compose content */ });
        section.Footer(footer => 
        {
            footer
                .Paragraph(p =>
                {
                    p.Text("Page ");
                    p.CurrentPageNumber();
                    p.Text(" of ");
                    p.TotalPages();
                })
                .Center();
        });
    });
});
Content

Formatting

Page numbers are formatted by providing a PageNumberFormat argument. For example, the following code displays page numbers in lowercase Roman numerals:

footer
  .Paragraph(p => p.CurrentPageNumber(PageNumberFormat.RomanLowercase))
  .AlignCenter();

The following formats are supported:

EnumPreviewDescription
AlphabeticLowercasea, b, cOne or more occurrences of an lowercase alphabetic Latin character.
AlphabeticUppercaseA, B, COne or more occurrences of an lowercase alphabetic Latin character.
Arabic1, 2, 3Arabic cardinal numerals.
ArabicDashed- 1 -, - 2 -, - 3 -Arabic cardinal numerals, with a prefix of "-" and a suffix of "-".
RomanLowercasei, ii, iiiLowercase Roman numerals.
RomanUppercaseI, II, IIIUppercase Roman numerals.