Skip to Content
NexPDF

Platform notes

Threading, the cost of base64 over the bridge, memory, app size and deployment notes for NexPDF for React Native on iOS and Android.

English

Threading

The engine never runs on the JavaScript thread or the UI thread. The native module sends every call to one background thread: a serial dispatch queue on iOS, a single worker thread (nexpdf-rn) on Android.

  • Calls run one at a time, in the order you made them, across every document. Promise.all does not make them run in parallel; it only waits for all of them.
  • A long call (OCR, Office conversion, signing with LTV, a 300 dpi render) delays every call made after it, including a quick pageCount() or a render for the screen. Run long jobs when the user expects to wait, and show progress.
  • Because calls never overlap, you do not need to coordinate access to a document yourself: the engine's rule that a document is used by one thread at a time always holds.
  • The license is process-wide: one activateLicense call covers every document and the reader.

The reader is presented on the main thread and runs its own engine work natively. While it is open, your JavaScript keeps running and receives its events.

Base64 and the bridge

Every call is one JSON string passed to the native module, and byte buffers travel as base64 strings inside it. This keeps the module small, but large buffers have a cost:

  • base64 is a third larger than the bytes: a 30 MB PDF is a 40 MB string;
  • the request is built with JSON.stringify and the reply read with JSON.parse on the JavaScript thread, so a very large buffer can drop frames while it is converted;
  • the string is copied from JavaScript to native code and decoded to bytes there, and results (saveBytes, renderPage, toDocx) make the same trip back, so a large file briefly exists in several copies.

Calls that pass only a document handle, numbers and short strings are cheap. To keep the cost low:

  • open a document once and keep it open while the user works with it; only its handle crosses the bridge after that;
  • render at the size you display, and use renderThumbPng(page, maxDim) for lists and grids;
  • call saveBytes() when the user saves, not after every edit;
  • read and write files with your file-system library's base64 functions; the SDK takes no file paths.

Memory

  • A document is read fully into native memory when it is opened. Budget roughly the file size plus the decoded pages you touch, plus the base64 copies while a buffer crosses the bridge.
  • Documents are freed only by await doc.close(). There is no finalizer, and reloading the JavaScript bundle (during development, or with an over-the-air update) does not free the documents the previous bundle opened. Close documents in a finally block.
  • The renderer keeps process-wide caches of parsed fonts, glyphs and decoded images, shared by every document. Each cache is bounded by size and drops its least recently used entries first; together they can hold up to about 1.3 GB on a process that renders many large, image-heavy files. On a phone the system can stop a background app long before that, so render at display size and close what you no longer show.
  • memoryUsageBytes() estimates the memory one document uses, and trimMemory() (1.1 and later) compacts the buffers of a long-lived, often edited document. See Compare and optimise.
  • Neural OCR models stay loaded for the whole app process once NexPdf.api.ocrLoadModel loads them; NexPdf.api.ocrUnloadModels frees them. See OCR.

Packaging and app size

The package itself is TypeScript plus two small native modules. The engine comes from the native SDKs it depends on:

PlatformDependencyWhat it adds
iOSNexPdf pod (NexPdfCore.xcframework) and NexPdfUI podThe engine, linked statically into the app binary, and the reader UI
Androidcom.nexdevit:nexpdf-android AARlibnexpdf_ffi.so and its JNI bridge for arm64-v8a, armeabi-v7a and x86_64, and the reader activity
  • On Android the engine library is about 20 MB per ABI, uncompressed. With an Android App Bundle, Google Play delivers only the device's ABI. A universal APK carries all three; use abiFilters or ABI splits if you distribute APKs yourself.
  • On iOS the engine is linked statically, and a device build links only the ios-arm64 slice of the xcframework. The .a files in the xcframework are much larger than what ends up in the app, because they hold everything the linker may need. Measure the real size with Xcode's App Thinning Size Report.
  • The reader UI is always included: the iOS module depends on NexPdfUI, and the Android module starts NexPdfReaderActivity from the AAR.
  • The default engine compiles in the Liberation fonts (about 4 MB) used for non-embedded standard fonts and PDF/A. NexPdf.api.hasBundledFonts() tells you which build you have.

Requirements

React Native0.72 or later
iOS15.0 or later, Swift 5.9
AndroidminSdk 24, compileSdk 35, Java 17

The module is a classic native module (NativeModules.NexPdf); it has no TurboModule spec.

Deployment

  • Keys are bound to a platform and an app id. The SDK picks ios or android from Platform.OS; pass the bundle id on iOS and the package name on Android. Debug builds with an applicationIdSuffix have a different package name.
  • On Android, the reader writes the document you pass to NexPdfReader.open to the app's cache folder (nexpdf-reader/) before it opens it. On iOS it opens it from memory.
  • Ship the license key with the app (for example as a bundled asset or a build-time constant) and activate it at every launch; activation is offline.

Network

The engine makes no network calls of its own: license keys are verified offline and documents never leave the device. Only signing options you set (tsa_url for a timestamp, ltv for OCSP and CRL lookups) and NexPdf.api.addLtv contact the servers named in the certificates. On Android these need the INTERNET permission, which React Native apps declare by default.

On this page