PageNavigation Class
Provides functionality for managing and navigating through pages in a PDF document.
export declare class PageNavigation implements EventElement<PageEventMap>
- Inheritance:
-
PageNavigation
Implements
Remarks
This class handles page navigation, including setting the current page, moving to next/previous pages, and emitting events when page changes occur. It extends EventElement to support event-based communication.
Properties
numberOfPages
Gets the total number of pages in the currently loaded PDF document.
get numberOfPages(): number;
Remarks
This property returns the count of pages available in the document. The value is updated automatically when a new document is loaded or when the page count changes.
currentPage
Gets the current page index that is being displayed.
get currentPage(): number;
Remarks
This property returns the zero-based index of the currently active page. The value is updated automatically when navigation occurs or when a new page is set programmatically.
Methods
addEventListener(K, (event: PageEventMap[K]) => void)
Adds an event listener for the specified event type.
addEventListener<K extends keyof PageEventMap>(type: K, listener: (event: PageEventMap[K]) => void): void;
Parameters
-
type
The event type/name to listen for.
-
listener
The callback function that will be invoked when the event is emitted.
setCurrentPage(number)
Sets the current page to display in the PDF viewer.
setCurrentPage(page: number): void;
Parameters
-
page
The page index to navigate to (zero-based index).
Remarks
This method changes the currently displayed page. It validates that the requested page index is within bounds before attempting to change pages. If the page index is invalid, the method returns without making any changes. The method emits a pageChanging event before changing the page, allowing listeners to cancel or modify the navigation. If the event is not prevented, the current page index is updated. The method also handles the case where the page index is out of bounds and prevents invalid navigation.
nextPage
Navigates to the next page in the PDF document.
nextPage(): void;
Remarks
This convenience method increments the current page index by 1 and calls setPage internally. If already on the last page, this method has no effect.
previousPage
Navigates to the previous page in the PDF document.
previousPage(): void;
Remarks
This convenience method decrements the current page index by 1 and calls setPage internally. If already on the first page, this method has no effect.