Reader
Present the native NexPDF reader from Flutter on iOS and Android, or embed the pure-Flutter viewer widget, and configure both with the shared UI configuration.
The native reader
import 'package:nexpdf_flutter/nexpdf_flutter.dart';
final config = NexPdfUIConfig.fromJson({
'modeConfig': {'availableModes': ['viewer', 'annotations', 'forms']},
'toolbarConfig': {
'customItems': [
{'id': 'send', 'title': 'Send', 'icon': 'send', 'location': 'top'},
],
},
'globalConfig': {'accentColor': '#0F766E', 'themeMode': 'dark', 'language': 'pt'},
});
final sub = NexPdfReader.events.listen((e) {
if (e.type == 'customItemTapped' && e.data['id'] == 'send') {
NexPdfReader.close();
}
});
await NexPdfReader.open(document: pdfBytes, fileName: 'contract.pdf', config: config);NexPdfReader.open({document, fileName, config})presents the reader and completes once it is shown.documentis a PDF, or a Word, Excel or PowerPoint file; without one the reader opens empty with its Open button.NexPdfReader.close()closes it.NexPdfReader.eventsis a broadcast stream ofNexPdfReaderEvents with atypeanddata.
The reader has the modes viewer, annotations, content (text and image editing), forms and redaction, plus search, a page editor, bookmarks, attachments and signatures. The user saves the edited file from the reader itself; the plugin has no call that returns the edited document to Dart.
Events
| Event | data |
|---|---|
documentLoaded, documentChanged | filename, pageCount, canUndo, canRedo |
modeChanged | mode |
pageChanged | page (1-based), pageCount |
customItemTapped | id, mode, page |
closed | filename |
The Flutter viewer widget
NexPdfViewerWidget renders a NexPdfDocument with page swiping, pinch zoom, search with
highlights and a pages grid:
final doc = sdk.open(pdfBytes);
Navigator.push(context, MaterialPageRoute(
builder: (_) => NexPdfViewerWidget(
document: doc,
config: config,
onEvent: (type, data) => debugPrint('$type $data'),
),
));The widget does not dispose the document: call doc.dispose() when you are done with it. Its
events are documentLoaded, pageChanged, modeChanged, customItemTapped, searchOpened and
searchCompleted (query, count).
Configuration
NexPdfUIConfig holds the shared NexPDF UI configuration. Build it with
NexPdfUIConfig.fromJson(map), or parse JSON text with NexPdfUIConfig.parse(source), which gives
the defaults for invalid JSON. Every key is optional and unknown keys are ignored.
final json = await rootBundle.loadString('assets/nexpdf_ui_config.json');
final config = NexPdfUIConfig.parse(json);| Key | Native reader | NexPdfViewerWidget |
|---|---|---|
modeConfig (initial, available, read-only) | Yes | viewer, annotations, content, pages |
toolbarConfig.hiddenItems | Yes | modeSwitcher, search, pages, more |
toolbarConfig.customItems (top, toolbar, more) | Yes | Yes |
annotationsConfig.availableTools | Yes | Yes |
formsConfig.availableTools | Yes | No |
| Default colour, opacity, palette, presets, stamps | Yes | No |
readerConfig.nightMode | Yes | No |
globalConfig.themeMode, accentColor | Yes | Yes |
globalConfig.language, strings, languages | Yes | String overrides only |
Layout, zoom, item order, defaultFontSize, brand and CSS keys are web only. The native reader
supports exactly what the iOS and
Android readers support.