Reader
Present the ready-made NexPDF reader screen in a React Native app on iOS and Android, customise it with the shared UI configuration, and listen to its events.
NexPdfReader presents the full NexPDF reader screen, the same one as in the iOS and Android SDKs:
viewing, annotations, forms, signatures, redaction and the other modes your license includes. You
customise it with the shared UI configuration.
Open the reader
import { NexPdfReader } from '@nexdevit/nexpdf-react-native';
const sub = NexPdfReader.addListener('customItemTapped', ({ id }) => console.log('tapped', id));
await NexPdfReader.open({
document: base64Pdf,
fileName: 'contract.pdf',
config: {
modeConfig: { availableModes: ['viewer', 'annotations'] },
toolbarConfig: { customItems: [{ id: 'send', title: 'Send', icon: 'send', location: 'top' }] },
globalConfig: { accentColor: '#0F766E', language: 'pt' },
},
});| Option | Meaning |
|---|---|
document | The PDF (or DOCX, XLSX, PPTX) as base64. Without it the reader opens empty, with its Open button |
fileName | The name shown in the reader, default document.pdf |
config | The UI configuration, see below |
open resolves once the reader is shown, full screen. NexPdfReader.close() closes it. Listen for
closed to know when the user dismisses it.
Events
addListener(type, listener) subscribes to one event and returns a subscription; call remove() on
it to stop.
const subs = [
NexPdfReader.addListener('documentChanged', ({ filename, pageCount, canUndo }) => setDirty(canUndo)),
NexPdfReader.addListener('pageChanged', ({ page, pageCount }) => console.log(page, pageCount)),
NexPdfReader.addListener('closed', () => subs.forEach((s) => s.remove())),
];| Event | Data |
|---|---|
documentLoaded, documentChanged | filename, pageCount, canUndo, canRedo |
modeChanged | mode |
pageChanged | page (1-based), pageCount |
customItemTapped | id, mode, page |
closed | filename: the reader screen was closed |
UI configuration
The same JSON configuration customises the NexPDF readers on the web, iOS, Android and Electron. Every key is optional, and unknown keys and ids are ignored.
| Key | What it does |
|---|---|
modeConfig.initialMode | The mode the reader opens in: viewer, annotations, content, pages, forms, signatures, security, redaction, measurement or ai |
modeConfig.availableModes | The modes the user can switch to, in this order. With one mode the switcher is hidden |
modeConfig.readOnly | Viewing only: the viewer mode alone, without undo, redo, open, the page editor or editing rows |
toolbarConfig.hiddenItems | Built-in items to hide, such as modeSwitcher, undo, redo, search, pages, more, share, close; More menu rows as menu.<id> |
toolbarConfig.customItems | Your buttons: { id, title, icon?, location?, modes? }. location is top, toolbar or more (the default). A tap sends customItemTapped |
annotationsConfig.availableTools | The annotation tools to offer, in this order |
annotationsConfig.defaultColor / defaultOpacity / colorPalette | The starting colour and opacity, and the swatches |
annotationsConfig.presets / rememberStyles | The style each tool starts with, and whether it remembers the last one |
annotationsConfig.stamps | The texts the stamp tool offers |
formsConfig.availableTools | The form field tools to offer |
readerConfig.nightMode | Shows pages with inverted colours |
globalConfig.themeMode / accentColor | system, light or dark, and the brand colour |
globalConfig.language / strings / languages | The interface language, text overrides and extra languages |
On iOS and Android the More menu also has menu.pageEditor, menu.handSignature,
menu.digitalSign, menu.flatten, menu.imageStamp and menu.license. Item order, the layout and
zoom, defaultFontSize, the brand and custom CSS are web-only and ignored here. See the
web viewer for the full list of tools and ids.
Getting the edited document back
NexPdfReader has no call that returns the edited document to JavaScript. Users save or share it
from the reader itself (the share item). To change documents from code, use
PdfDocument instead.