Guides
Page Navigation
When displaying a PDF using the CPDFReaderView component, you can perform the following actions via the API:
Jump to a specific page
tsx
await pdfReaderRef.current?.setDisplayPageIndex(1);1
When you need to navigate to a specific page and simultaneously highlight certain content (for example, highlighting an annotation when clicked), you can use the rectList parameter of setDisplayPageIndex to draw rectangles on the page.
The following example shows how to jump to the page containing an annotation and highlight the annotation area with a rectangle:
tsx
const pageIndex = 0;
const page = pdfReaderRef?.current?._pdfDocument.pageAtIndex(pageIndex);
const annotations = await page?.getAnnotations();
const annotation = annotations![0];
await pdfReaderRef.current?.setDisplayPageIndex(pageIndex: annotation.page, { rectList: [annotation.rect!]});
// clear highlight area.
await pdfReaderRef.current?.clearDisplayRect();1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
Example Result:
| Android | iOS |
|---|---|
![]() | ![]() |
Get the current page number
tsx
const pageIndex = await pdfReaderRef.current?.getCurrentPageIndex();1
You can also set a page listener when using CPDFReaderView to get the current page number in real-time as you scroll.
tsx
const pdfReaderRef = useRef<CPDFReaderView>(null);
<CPDFReaderView
ref={pdfReaderRef}
document={samplePDF}
onPageChanged={onPageChanged}
configuration={ComPDFKit.getDefaultConfig({
})} />
const onPageChanged = (pageIndex: number) => {
console.log('ComPDFKitRN --- onPageChanged:', pageIndex);
}1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11

