rn-dev-pdfviewer
v1.0.2
Published
Hybrid PDF viewer for React Native (Android). Android 12+ uses AndroidX PdfViewerFragment, older versions use pdfium-based custom engine. Features: pinch zoom, text search with highlights, text copy, smooth scrolling, rotation support.
Maintainers
Readme
rn-dev-pdfviewer
Hybrid PDF viewer for React Native (Android). Automatically uses the best rendering engine for the device.
- Android 12+ — AndroidX PdfViewerFragment (Google engine, smooth zoom, built-in search, text selection & copy)
- Android < 12 — Custom pdfium-based engine (pinch zoom, text search with highlights, smooth scrolling)
Installation
npm install rn-dev-pdfviewer
# or
yarn add rn-dev-pdfviewerNo manual linking required — React Native auto-links the native module.
Usage
Inline Component
import PdfViewer from 'rn-dev-pdfviewer';
export default function App() {
return (
<PdfViewer
source="https://example.com/sample.pdf"
onLoadComplete={(e) => console.log(`Loaded ${e.nativeEvent.totalPages} pages`)}
onError={(e) => console.log(`Error: ${e.nativeEvent.message}`)}
style={{ flex: 1 }}
/>
);
}Full-Screen Native Activity
import { openPdf } from 'rn-dev-pdfviewer';
openPdf('https://example.com/sample.pdf');Props
| Prop | Type | Description |
|------|------|-------------|
| source | string | PDF URL to load (required) |
| onLoadComplete | function | Called when PDF is loaded. Returns { totalPages } |
| onPageChanged | function | Called on page change. Returns { page, totalPages } |
| onZoomChanged | function | Called on zoom. Returns { scale } |
| onError | function | Called on error. Returns { message } |
| onSearchResults | function | Called after search. Returns { totalMatches } |
| style | ViewStyle | Container style |
Ref Methods (Custom Engine)
const pdfRef = useRef(null);
<PdfViewer ref={pdfRef} source={url} />
// Available methods:
pdfRef.current.goToPage(5);
pdfRef.current.zoomIn();
pdfRef.current.zoomOut();
pdfRef.current.resetZoom();
pdfRef.current.search('keyword');
pdfRef.current.nextMatch();
pdfRef.current.prevMatch();
pdfRef.current.clearSearch();API
| Function | Description |
|----------|-------------|
| openPdf(url) | Opens PDF in full-screen native Activity |
| getViewerType() | Returns Promise<'androidx' \| 'custom'> |
Requirements
- React Native >= 0.72
- Android minSdk 21 (Android 5.0+)
- Android compileSdk 36
License
Proprietary — see LICENSE for details.
