Text
Page Numbers
Quickly insert fields for page numbers.
Document Related
The following methods allow you to insert page numbers within a paragraph:
| Method | Description |
|---|---|
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:
| Enum | Preview | Description |
|---|---|---|
AlphabeticLowercase | a, b, c | One or more occurrences of an lowercase alphabetic Latin character. |
AlphabeticUppercase | A, B, C | One or more occurrences of an lowercase alphabetic Latin character. |
Arabic | 1, 2, 3 | Arabic cardinal numerals. |
ArabicDashed | - 1 -, - 2 -, - 3 - | Arabic cardinal numerals, with a prefix of "-" and a suffix of "-". |
RomanLowercase | i, ii, iii | Lowercase Roman numerals. |
RomanUppercase | I, II, III | Uppercase Roman numerals. |