By default, each page
thumbnail displays the corresponding page number. It will replace the page number with a custom page label if there is any.
Here are a few examples where we will see custom page labels:
- The pages are numbered by the Roman numerals system such as i, ii, iii, etc.
- The document is extracted from another document. In this case, the page numbers in the original document will be displayed.
The following example displays the page labels of a sample document whose pages are extracted from another one:
Customize page labels
If you think this kind of page numbers are confusing to the users, then you can customize them.
Available from v2.10.0, the thumbnail plugin provides the `renderCurrentPageLabel`
option for customizing page labels:
import { thumbnailPlugin } from '@react-pdf-viewer/thumbnail';
const thumbnailPluginInstance = thumbnailPlugin({
renderCurrentPageLabel,
});
The `renderCurrentPageLabel`
option is a function that accepts a `RenderCurrentPageLabelProps`
parameter and returns a React element.
The `RenderCurrentPageLabelProps`
type consists of the following properties:
Property | Type | Description | From |
---|
`currentPage` | `number` | The current page number | 2.10.0 |
`numPages` | `number` | The total number of pages | 2.10.0 |
`pageIndex` | `number` | The page number of the corresponding page. It is the zero-based value | 2.10.0 |
`pageLabel` | `string` | The page label of the corresponding page | 2.10.0 |
The sample code below displays the page index and the page label if it is different than the page index:
import type { RenderCurrentPageLabel, RenderCurrentPageLabelProps } from '@react-pdf-viewer/thumbnail';
const renderCurrentPageLabel: RenderCurrentPageLabel = (props: RenderCurrentPageLabelProps) => (
<>
{props.pageIndex + 1}
{props.pageLabel !== `${props.pageIndex + 1}` && `(${props.pageLabel})`}
</>
);
const thumbnailPluginInstance = thumbnailPlugin({
renderCurrentPageLabel,
});
See also