Skip to main content

Quick Start (6.x)

import {useRef} from 'react';
import {PdfView, type PdfViewRef} from 'react-native-pdf-jsi';

export function Reader() {
const viewer = useRef<PdfViewRef>(null);

return (
<PdfView
ref={viewer}
style={{flex: 1}}
source={{uri: 'https://example.com/report.pdf', cache: 'persistent'}}
onLoad={({pageCount}) => {
console.log('pages', pageCount);
viewer.current?.goToPage(4);
viewer.current?.zoomTo(2, {animated: true});
}}
onPageChange={({page, pageCount}) => {
console.log(`${page + 1}/${pageCount}`);
}}
onError={(error) => console.warn(error.code, error.message)}
/>
);
}

Key v6 API differences​

  • Page indexes are 0-based.
  • onLoadComplete is replaced by onLoad.
  • onPageChanged is replaced by onPageChange.
  • fitPolicy is string-based: 'width' | 'height' | 'page'.

Source formats​

{uri: 'https://...', cache: 'session'}
{uri: 'https://...', cache: 'persistent'}
{filePath: '/path/to/file.pdf'}
{base64: 'JVBER...'}
require('./local.pdf')

Next: Migration to 6.0