Reader
Open the ready-made NexPDF reader activity in an Android app, configure its modes, toolbar, tools and theme, and react to its events.
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:
- the
configJsonof the intent (theNexPdfReaderActivity.EXTRA_CONFIGextra); assets/nexpdf_ui_config.json;- 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}}""")
}| Key | What it does on Android |
|---|---|
modeConfig.initialMode, availableModes | The mode to open in and the modes offered: viewer, annotations, content, forms, redaction. With one mode, the switcher is hidden |
modeConfig.readOnly | Viewing only: hides undo, redo, open, the page editor and every editing row |
toolbarConfig.hiddenItems | Built-in items to hide, such as search, pages, more, undo, redo, or More menu rows as menu.<id> |
toolbarConfig.customItems | Your own buttons: id, title, icon, location (top, toolbar or more) and modes |
annotationsConfig | availableTools, defaultColor, defaultOpacity, colorPalette, presets, rememberStyles, stamps |
formsConfig.availableTools | The form field tools to offer |
readerConfig.nightMode | Shows pages with inverted colours |
globalConfig | themeMode (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.
| Event | data |
|---|---|
documentLoaded, documentChanged | filename, pageCount, canUndo, canRedo |
modeChanged | mode |
pageChanged | page (1-based), pageCount |
customItemTapped | id, mode, page |
closed | filename |
NexPdfReaderActivity.setEventListener { type, data ->
if (type == "customItemTapped" && data.optString("id") == "send") {
NexPdfReaderActivity.closeCurrent()
upload()
}
}