NexPDF for Android
Render, extract, annotate, fill, edit, convert, sign and redact PDFs in Android apps with the NexPDF AAR, its JNI API and the ready-made reader activity.
NexPDF for Android (com.nexdevit:nexpdf-android) is an AAR with the native engine for
arm64-v8a, armeabi-v7a and x86_64, and three layers of API:
NexPdfDocument: a smallCloseableclass for the common tasks: open, render, extract text, search, convert to Markdown, JSON or Word, and save.NexPdfJni: static native methods for the rest of the engine. They take the document'slonghandle fromdoc.handle().NexPdfReaderActivity: the ready-made reader screen, configured with the shared UI configuration. See Reader.
Licensing is NexPdfLicense. The classes are Java and work the same from Kotlin.
import com.nexdevit.nexpdf.NexPdfDocument
import com.nexdevit.nexpdf.NexPdfJni
NexPdfDocument.openBytes(bytes).use { doc ->
val png = doc.renderPagePng(0, 144.0)
val text = doc.pageText(0)
val fields = NexPdfJni.formFieldsJson(doc.handle())
}Requirements
| Android | API 24 (Android 7.0) or later |
| ABIs | arm64-v8a, armeabi-v7a, x86_64 |
| Dependencies | None. The reader needs no AndroidX |
How it works
NexPdfDocumentwraps a native handle. Close it withclose(),use { }in Kotlin or try-with-resources in Java.handle()throwsIllegalStateExceptiononce it is closed.NexPdfDocument.openBytes,openEbook,openImage,openOffice,fromHtmland the template calls throwIllegalArgumentExceptionwith the engine's message when the file cannot be opened.openBytesconverts Office files, e-books and comics, andopenBytes(bytes, password)opens encrypted PDFs.NexPdfJnimethods do not throw. A failure returnsfalse,0,-1, an empty array or an empty string, andNexPdfJni.lastError()gives the reason on the same thread.- Methods whose name ends in
Jsonreturn JSON text; parse it withorg.json. - Page indices start at 0. Coordinates are PDF points with the origin at the bottom-left of the
page (
llx, lly, urx, ury). - Use one document from one thread at a time. Different documents can be used on different threads. Run long calls (rendering many pages, OCR, conversion) off the main thread.
Every C function has a Java method
Since 1.1, every function of the C API has a NexPdfJni method, including askDocument,
toHtml / toXml / toCsv / toRtf, saveLinearized, setOverprint, pageLabelsJson /
setPageLabelsJson, subsetFonts, convertPdfX, openEbook, openImage,
registerStandardFont, hasBundledFonts, clearError and the three external-signing calls, and
the 1.1 functions (templates, document timestamps, comment threads, structured extraction, XFA,
word-level comparison, barcodes, OCR models and PDF/A and PDF/UA validation). NexPdfDocument
wraps the common ones, and the sync calls are in NexPdfSyncJni (see
Real-time collaboration).
The generic invoke call
NexPdfJni.invoke still takes the whole C API as one JSON request, which suits bridges that only
pass strings. Function names are the C names without nexpdf_, byte buffers travel as base64 and
documents as handle numbers:
import android.util.Base64
import com.nexdevit.nexpdf.NexPdfJni
import org.json.JSONArray
import org.json.JSONObject
object NexPdfInvoke {
/** Calls a C function by name, without the nexpdf_ prefix. */
fun call(fn: String, vararg args: Any?): Any? {
val request = JSONObject().put("fn", fn).put("args", JSONArray(args.map { it ?: JSONObject.NULL }))
val response = JSONObject(NexPdfJni.invoke(request.toString()))
if (!response.getBoolean("ok")) throw IllegalStateException(response.getString("error"))
return response.opt("result")
}
fun base64(bytes: ByteArray): String = Base64.encodeToString(bytes, Base64.NO_WRAP)
/** Opens PDF bytes as an invoke document; close it with call("close", handle). */
fun open(pdf: ByteArray): Int = (call("open_bytes", base64(pdf)) as Number).toInt()
}Invoke handles are separate from the long handles of NexPdfJni: open the document's bytes with
NexPdfInvoke.open and free the handle with call("close", h). Prefer the typed methods in app
code.
Getting started
Installation
Gradle and the Maven repository.
Your first document
Open a PDF, render a page and extract its text.
Add your license key
Activate a key and handle license errors.
Running without a key
View-only mode, the watermark and trial keys.
Reader
The ready-made reader activity.
Guides
Opening and saving
Bytes, content URIs, passwords, pictures, HTML and Office input.
Rendering
Pages and thumbnails to PNG, coordinates.
Document structure
Metadata, bookmarks, page labels, layers, attachments.
Text extraction
Text, Markdown, positioned blocks, passages for LLMs.
Search
Find text and its rectangles.
OCR
Make scanned pages searchable, in any script.
Structured extraction
Tables, key-values, schema extraction with your LLM, classification.
Barcodes
Read QR, Data Matrix, PDF417 and linear codes; draw barcodes.
Annotations
Markup, shapes, ink, stamps, measurements, XFDF.
Forms
Fill, create, calculate, flatten, import and export.
XFA forms
Run FormCalc and JavaScript, lay out dynamic forms, convert to AcroForm, flatten.
Comment threads
Replies and review states on annotations.
Real-time collaboration
Sync pages, annotations, comments, form values and bookmarks with NexPdfSyncClient.
Editing
Merge, split, reorder, crop; edit text and images.
Compare and optimise
Diff versions, shrink files, control memory.
Word-level comparison
Inserted, deleted, replaced and moved text; annotated PDF.
Security
Encryption, permissions, watermarks, Bates numbers.
Redaction
Remove content for good by area, text or pattern.
Signatures
PAdES signing, external signers, verification.
Long-term signatures
PAdES B-LTA, document and archive timestamps.
Conversion
PDF to Word, Excel, PowerPoint, HTML and more.
Templates
PDFs from Word, HTML and PDF templates and JSON data.
PDF/A, PDF/X and PDF/UA
Archiving, print and accessibility.
PDF/A and PDF/UA validation
PDF/A and PDF/UA-1 and -2 with clause ids; convert to PDF/A or PDF/UA.