Skip to Content
NexPDF

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.

English

Two readers

NexPdfReader presents the native reader of the iOS and Android SDKs full screen. NexPdfViewerWidget is a Flutter widget that works on mobile and desktop with fewer features. The native reader's editing modes need the license module of each feature; viewing works without a key.

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. document is a PDF, or a Word, Excel or PowerPoint file; without one the reader opens empty with its Open button.
  • NexPdfReader.close() closes it.
  • NexPdfReader.events is a broadcast stream of NexPdfReaderEvents with a type and data.

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

Eventdata
documentLoaded, documentChangedfilename, pageCount, canUndo, canRedo
modeChangedmode
pageChangedpage (1-based), pageCount
customItemTappedid, mode, page
closedfilename

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);
KeyNative readerNexPdfViewerWidget
modeConfig (initial, available, read-only)Yesviewer, annotations, content, pages
toolbarConfig.hiddenItemsYesmodeSwitcher, search, pages, more
toolbarConfig.customItems (top, toolbar, more)YesYes
annotationsConfig.availableToolsYesYes
formsConfig.availableToolsYesNo
Default colour, opacity, palette, presets, stampsYesNo
readerConfig.nightModeYesNo
globalConfig.themeMode, accentColorYesYes
globalConfig.language, strings, languagesYesString 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.

On this page