Skip to Content
NexPDF

Reader

Open the ready-made NexPDF reader activity in an Android app, configure its modes, toolbar, tools and theme, and react to its events.

English

NexPdfReaderActivity

The reader is com.nexdevit.nexpdf.ui.NexPdfReaderActivity, part of the AAR and already declared in its manifest. Its editing modes call the same engine functions as the API, so each needs the license module of that feature; viewing works without a key.

The reader is a complete PDF screen: page view, search, thumbnails, page editor, bookmarks, attachments, a More menu with security, signatures, OCR, PDF/A, export and more, and the modes viewer, annotations, content (text and image editing), forms and redaction. It needs no AndroidX.

Open the reader

import com.nexdevit.nexpdf.ui.NexPdfReaderActivity

NexPdfReaderActivity.setEventListener { type, data ->
    Log.d("NexPDF", "$type $data")
}
startActivity(NexPdfReaderActivity.intent(this, pdfUri, null))

intent(context, document, configJson) takes a content: or file: URI (or null to open the reader empty, with its Open button) and the configuration JSON (or null). The intent grants the reader read access to the URI.

NexPdfReaderActivity.closeCurrent() closes the reader that is on screen. The user saves the edited PDF with Save as in the More menu.

Configure it

The configuration is the shared NexPDF UI configuration, the same JSON as on the web, iOS, Flutter and React Native. Every key is optional and unknown keys are ignored.

val config = """
{
  "modeConfig": { "initialMode": "annotations", "availableModes": ["viewer", "annotations", "forms"] },
  "toolbarConfig": {
    "hiddenItems": ["search", "menu.ocr"],
    "customItems": [{ "id": "send", "title": "Send to CRM", "icon": "send", "location": "top" }]
  },
  "annotationsConfig": { "availableTools": ["ink", "highlight", "note"], "defaultColor": "#0F766E" },
  "globalConfig": { "themeMode": "dark", "accentColor": "#0F766E", "language": "pt" }
}
"""
startActivity(NexPdfReaderActivity.intent(this, pdfUri, config))

The reader takes its configuration from, in order:

  1. the configJson of the intent (the NexPdfReaderActivity.EXTRA_CONFIG extra);
  2. assets/nexpdf_ui_config.json;
  3. the defaults.

To build the configuration in code, subclass the activity, override loadConfig() and declare your subclass in the manifest:

class MyReaderActivity : NexPdfReaderActivity() {
    override fun loadConfig(): NexPdfUIConfig =
        NexPdfUIConfig.parseOrEmpty("""{"modeConfig":{"readOnly":true}}""")
}
KeyWhat it does on Android
modeConfig.initialMode, availableModesThe mode to open in and the modes offered: viewer, annotations, content, forms, redaction. With one mode, the switcher is hidden
modeConfig.readOnlyViewing only: hides undo, redo, open, the page editor and every editing row
toolbarConfig.hiddenItemsBuilt-in items to hide, such as search, pages, more, undo, redo, or More menu rows as menu.<id>
toolbarConfig.customItemsYour own buttons: id, title, icon, location (top, toolbar or more) and modes
annotationsConfigavailableTools, defaultColor, defaultOpacity, colorPalette, presets, rememberStyles, stamps
formsConfig.availableToolsThe form field tools to offer
readerConfig.nightModeShows pages with inverted colours
globalConfigthemeMode (system, light, dark), accentColor, language, strings, languages

Layout, zoom, item order, defaultFontSize, brand and CSS keys are web only and are ignored on Android.

Events

setEventListener receives the events of every reader on the main thread, as a type and an org.json.JSONObject. Pass null to stop.

Eventdata
documentLoaded, documentChangedfilename, pageCount, canUndo, canRedo
modeChangedmode
pageChangedpage (1-based), pageCount
customItemTappedid, mode, page
closedfilename
NexPdfReaderActivity.setEventListener { type, data ->
    if (type == "customItemTapped" && data.optString("id") == "send") {
        NexPdfReaderActivity.closeCurrent()
        upload()
    }
}

On this page