📘
prose
  • Get Started
    • Introduction
    • Demo & Showcase
    • Contact / Community / Links
    • Getting started
    • Core concepts
    • Troubleshooting / FAQ
  • Alternatives
  • Learn
    • Core
    • Streamer
      • Node
      • React Native
      • Service Worker
      • Web (dom)
      • Hooks
    • Enhancers
    • Viewport
    • Hooks
    • Pagination
    • Settings
    • Context
    • Navigation
    • Selection
    • Links
    • Zoom
    • PDF
  • CORE API
    • reader
      • links$
      • locateResource()
    • viewport
    • navigation
  • zoom
  • enhancers
    • PDF
    • Gestures
    • Gallery
    • Search
    • Annotations
    • Bookmarks
  • React Reader
    • Introduction
    • Getting Started
  • CFI
    • About
Powered by GitBook
On this page
  • type PaginationInfo
  • pagination.paginationInfo$
  • Examples
  • pagination.getPaginationInfo()

Was this helpful?

  1. Learn

Pagination

reader.pagination gives you access to the current book pagination information. It can be used to know which page is being read, how many pages are in a chapters or other such information.

type PaginationInfo

type PaginationInfo = {
  beginCfi: string | undefined
  beginSpineItemIndex: number | undefined
  beginChapterInfo: ChapterInfo | undefined
  beginPageIndexInSpineItem: number | undefined
  beginNumberOfPagesInSpineItem: number | undefined
  beginSpineItemReadingDirection: `rtl` | `ltr` | undefined
  beginAbsolutePageIndex: number | undefined
  endCfi: string | undefined
  endSpineItemIndex: number | undefined
  endChapterInfo: ChapterInfo | undefined
  endPageIndexInSpineItem: number | undefined
  endNumberOfPagesInSpineItem: number
  endSpineItemReadingDirection: `rtl` | `ltr` | undefined
  endAbsolutePageIndex: number | undefined
  /*
   * This percentage is based of the weight (kb) of every items and the number of pages.
   * It is not accurate but gives a general good idea of the overall progress.
   */
  percentageEstimateOfBook: number | undefined
  /**
   * This value is only correct for pre-paginated books and or
   * if you preload the entire book in case of reflow. This is because
   * items get loaded unloaded when navigating through the book, meaning
   * we cannot measure the number of pages accurately.
   */
  numberOfTotalPages: number | undefined
  isUsingSpread: boolean
  canGoLeft: boolean
  canGoRight: boolean
}

pagination.paginationInfo$

Observable<PaginationInfo>

Observable that emit whenever a new valid pagination info is updated. It will not emit invalid pagination.

Examples

Save current cfi into localStorage for loading a book at the previous location:

// save cfi into localstorage
reader.pagination.paginationInfo$.subscribe((paginationInfo) => {
    localStorage.setItem(`cfi`, paginationInfo.beginCfi)
})

// when we load the book
reader.load(manifest, {
    containerElement: document.getElementById(`reader`),
    cfi: localStorage.getItem(`cfi`)
})

pagination.getPaginationInfo()

PaginationInfo

Static method to return the pagination info. Be careful since it can return an invalid pagination (For example if no book is loaded).

PreviousHooksNextSettings

Last updated 5 months ago

Was this helpful?